在我的应用程序中,我想使用代码/编程方式打开设备默认日历。我正在使用此代码:
private void viewAllCalender() {
// TODO Auto-generated method stub
Intent i = new Intent();
if(Build.VERSION.SDK_INT >= 8 && Build.VERSION.SDK_INT <= 14){
i.setClassName("com.android.calendar","com.android.calendar.LaunchActivity");
}else if(Build.VERSION.SDK_INT >= 15){
i.setClassName("com.google.android.calendar", "com.android.calendar.LaunchActivity");
}else{
i.setClassName("com.android.calendar","com.android.calendar.LaunchActivity");
}
startActivity(i);
}
它正在为所有设备工作但是它不在SAMSUNG S3中工作 - (构建SDK版本 - 17)
请帮我弄清问题是什么?
由于
答案 0 :(得分:2)
你必须意识到你不能指望某个Android设备拥有某个应用程序。甚至不能安装播放应用程序。这样做的正确方法是不使用.setClassName,然后让用户决定该做什么。
有十几个不同的日历应用程序,手机制造商各有自己的......
修改强>
如果你想在日历中添加一个事件,你可以使用我的CalendarOrganizer处理很多这些问题:
public class CalendarOrganizer {
private final static int ICE_CREAM_BUILD_ID = 14;
/**
* Creates a calendar intent going from startTime to endTime
* @param startTime
* @param endTime
* @param context
* @return true if the intent can be handled and was started,
* false if the intent can't be handled
*/
public static boolean createEvent(long startTime, long endTime, String title, String description,
String location, boolean isAllDay, Context context) {
Intent intent = new Intent(Intent.ACTION_EDIT);
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < ICE_CREAM_BUILD_ID) {
// all SDK below ice cream sandwich
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);
// intent.putExtra("rrule", "FREQ=YEARLY");
} else {
// ice cream sandwich and above
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);
// intent.putExtra(Events.RRULE, "FREQ=DAILY;COUNT=10")
}
try {
context.startActivity(intent);
return true;
} catch(Exception e) {
return false;
}
}
}
答案 1 :(得分:0)
要打开日历应用程序,请参阅intent-view指南http://developer.android.com/guide/topics/providers/calendar-provider.html#intent-view