本文介绍了要添加事件的Android压延的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我开发一个Android应用程序中,我想处理日历。我无法在自己的日历中添加事件。我已经使用下列code。使用code,我能够在默认日历添加事件..请建议我需要在我的code在我的应用程序的日历添加事件的变化
私人无效的addEvent(){
// TODO自动生成方法存根
意图calIntent =新的意图(Intent.ACTION_INSERT);
calIntent.setType(vnd.android.cursor.item /事件);
calIntent.putExtra(Events.TITLE,我的房子党);
calIntent.putExtra(Events.EVENT_LOCATION,我的海滨别墅);
calIntent.putExtra(Events.DESCRIPTION,A烤猪上海滩);
GregorianCalendar的calDate =新的GregorianCalendar(2013,4,16);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY,真正的);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
calDate.getTimeInMillis());
calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
calDate.getTimeInMillis());
startActivity(calIntent);
Toast.makeText(这一点,活动增加了,Toast.LENGTH_SHORT).show();
}
解决方案
如果添加事件在下面code压延机的使用,在我的日历这项工作。
//这个code在压延加事件。
ContentResolver的CR = getContentResolver();
ContentValues值=新ContentValues();
values.put(Events.ALL_DAY,Events.ALL_DAY_VALUE);
values.put(Events.DTSTART,startTimeInMilli);
values.put(Events.DTEND,endTimeInMilli);
values.put(Events.TITLE,strTaskName);
values.put(Events.DESCRIPTION,还有strDescription);
values.put(Events.CALENDAR_ID,0);
values.put(Events.VISIBILITY,Events.VISIBILITY_VALUE);
乌里EVENTS_URI = Uri.parse(getCalendarUriBase(本)+事件);
开放的我们的uri = cr.insert(EVENTS_URI,价值观);
长事件ID =的Long.parseLong(uri.getLastPathSegment());
//这个函数调用上code。
私人字符串getCalendarUriBase(活动行为){
字符串calendarUriBase = NULL;
乌里日历= Uri.parse(内容://日历/日历);
光标managedCursor = NULL;
尝试 {
managedCursor = act.managedQuery(日历,NULL,NULL,NULL,NULL);
}赶上(例外五){
}
如果(managedCursor!= NULL){
calendarUriBase =内容://日历/;
} 其他 {
日历= Uri.parse(内容://com.android.calendar/calendars);
尝试 {
managedCursor = act.managedQuery(日历,NULL,NULL,NULL,
空值);
}赶上(例外五){
}
如果(managedCursor!= NULL){
calendarUriBase =内容://com.android.calendar/;
}
}
返回calendarUriBase;
}
//其他静态类事件常量。
公共类活动{
公共静态字符串ALL_DAY =allDay;
公共静态字符串DTSTART =DTSTART;
公共静态字符串DTEND =DTEND;
公共静态字符串TITLE =称号;
公共静态字符串描述=说明;
公共静态字符串CALENDAR_ID =CALENDAR_ID;
公共静态字符串EVENT_TIMEZONE =eventTimezone;
公共静态字符串能见度=知名度;
公共静态字符串HASALARM =hasAlarm;
公共静态INT VISIBILITY_VALUE = 0;
公共静态INT HASALARM_VALUE = 1;
公共静态INT ALL_DAY_VALUE = 0;
}
HI I am developing a android app in which I am suppose to handle calendar . I am unable to add event in my own calendar . I have used following code . using that code I am able to add event in a default calendar .. please suggest me the changes needed in my code to add event in the calendar of my app
private void addevent() {
// TODO Auto-generated method stub
Intent calIntent = new Intent(Intent.ACTION_INSERT);
calIntent.setType("vnd.android.cursor.item/event");
calIntent.putExtra(Events.TITLE, "My House Party");
calIntent.putExtra(Events.EVENT_LOCATION, "My Beach House");
calIntent.putExtra(Events.DESCRIPTION, "A Pig Roast on the Beach");
GregorianCalendar calDate = new GregorianCalendar(2013, 4, 16);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
calDate.getTimeInMillis());
calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
calDate.getTimeInMillis());
startActivity(calIntent);
Toast.makeText(this, "event added", Toast.LENGTH_SHORT).show();
}
解决方案
if add event in calender use below code , that work in my calender.
// this code for add event in calender.
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.ALL_DAY, Events.ALL_DAY_VALUE);
values.put(Events.DTSTART, startTimeInMilli);
values.put(Events.DTEND, endTimeInMilli);
values.put(Events.TITLE, strTaskName);
values.put(Events.DESCRIPTION, strDescription);
values.put(Events.CALENDAR_ID, 0);
values.put(Events.VISIBILITY, Events.VISIBILITY_VALUE);
Uri EVENTS_URI = Uri.parse(getCalendarUriBase(this) + "events");
Uri uri = cr.insert(EVENTS_URI, values);
long eventID = Long.parseLong(uri.getLastPathSegment());
// this function call upper code.
private String getCalendarUriBase(Activity act) {
String calendarUriBase = null;
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = null;
try {
managedCursor = act.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://calendar/";
} else {
calendars = Uri.parse("content://com.android.calendar/calendars");
try {
managedCursor = act.managedQuery(calendars, null, null, null,
null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://com.android.calendar/";
}
}
return calendarUriBase;
}
// other static class for event constants.
public class Events {
public static String ALL_DAY = "allDay";
public static String DTSTART = "dtstart";
public static String DTEND = "dtend";
public static String TITLE = "title";
public static String DESCRIPTION = "description";
public static String CALENDAR_ID = "calendar_id";
public static String EVENT_TIMEZONE = "eventTimezone";
public static String VISIBILITY = "visibility";
public static String HASALARM = "hasAlarm";
public static int VISIBILITY_VALUE = 0;
public static int HASALARM_VALUE = 1;
public static int ALL_DAY_VALUE = 0;
}
这篇关于要添加事件的Android压延的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!