安卓日历

4
ComponentName componentName = new ComponentName("com.android.calendar",
        "com.android.calendar.LaunchActivity");
if (componentName != null) {
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
    // com.android.providers.calendar.CalendarProvider
    intent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

    intent.setComponent(componentName);
    startActivity(intent);
} else {
    Log.i("", "98979");
}

LogCat 返回以下错误:

ERROR/AndroidRuntime(601): Caused by: android.content.ActivityNotFoundException:
Unable to find explicit activity class {com.android.calendar/com.android.calendar.LaunchActivity};
have you declared this activity in your AndroidManifest.xml?

新的日历地址或包名是什么?


2
你好,能否编辑你的问题并适当格式化代码片段?这是 Stack Overflow 的语法参考:http://stackoverflow.com/editing-help - Roman Nurik
请帮助这个线程: http://stackoverflow.com/questions/37658179/android-calendar-show-continuous-event-that-extends-for-2-or-more-days - Pradeep Kumar Kushwaha
3个回答

3

你可以尝试以下方法,

对我来说有效,可用于打开谷歌日历而非手机自带的日历应用。

 Intent i = new Intent();

//Froyo or greater (mind you I just tested this on CM7 and the less than froyo one worked so it    depends on the phone...)
cn = new ComponentName("com.google.android.calendar", "com.android.calendar.LaunchActivity");

 //less than Froyo
 cn = new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity");

i.setComponent(cn);
startActivity(i);

我正在寻找打开手机日历的方法。

3

尝试使用以下方法打开移动设备的日历...

int sdk = android.os.Build.VERSION.SDK_INT;
int ICE_CREAM_BUILD_ID = android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
if(sdk < ICE_CREAM_BUILD_ID) {
    // all SDK below ice cream sandwich
    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra("beginTime", startTime);
    intent.putExtra("endTime", endTime);
    intent.putExtra("title", title);
    intent.putExtra("description", description);
    intent.putExtra("eventLocation", location);
    intent.putExtra("allDay", isAllDay);
    startActivity(intent);
} else {
    // ice cream sandwich and above
    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTime);
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime);
    intent.putExtra(Events.TITLE, title);
    intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
    intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY , isAllDay);
    intent.putExtra(Events.DESCRIPTION, description);
    intent.putExtra(Events.EVENT_LOCATION, location);

    startActivity(intent);
}

1

这仅适用于通用的安卓手机。在制造商实现了自己的日历的手机上,日历类的类名将会不同。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接