Android 无法查看日历
在我的应用程序中,我希望以代码/编程方式打开设备默认日历。我正在使用以下代码:Android 无法查看日历,android,calendar,samsung-mobile,Android,Calendar,Samsung Mobile,在我的应用程序中,我希望以代码/编程方式打开设备默认日历。我正在使用以下代码: private void viewAllCalender() { // TODO Auto-generated method stub Intent i = new Intent(); if(Build.VERSION.SDK_INT >= 8 && Build.VERSION.SDK_INT <= 14){ i.se
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);
}
private void viewerallcalendar(){
//TODO自动生成的方法存根
意图i=新意图();
如果(Build.VERSION.SDK_INT>=8&&Build.VERSION.SDK_INT=15){
i、 setClassName(“com.google.android.calendar”、“com.android.calendar.LaunchActivity”);
}否则{
i、 setClassName(“com.android.calendar”、“com.android.calendar.LaunchActivity”);
}
星触觉(i);
}
它适用于所有设备,但不适用于三星S3-(构建SDK版本-17)
请帮我找出问题出在哪里
谢谢你,你必须意识到你不能指望Android设备有特定的应用程序。甚至连play应用程序都无法安装。正确的方法是不使用.setClassName,然后让用户决定要做什么 有十几种不同的日历应用,手机制造商都有自己的 编辑 如果要将事件添加到日历中,可以使用my 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;
}
}
}
公共类日历管理器{
私人最终静态int冰淇淋构建ID=14;
/**
*创建从开始时间到结束时间的日历
*@param startTime
*@param endTime
*@param上下文
*@return true如果可以处理并启动意图,
*如果无法处理意图,则为false
*/
公共静态布尔createEvent(长开始时间、长结束时间、字符串标题、字符串描述、,
字符串位置、布尔值(isAllDay、上下文){
意向意向=新意向(意向.行动\编辑);
int sdk=android.os.Build.VERSION.sdk\u int;
如果(sdk<冰淇淋\u构建\u ID){
//所有的冰淇淋三明治
intent.setType(“vnd.android.cursor.item/event”);
intent.putExtra(“开始时间”,开始时间);
intent.putExtra(“结束时间”,结束时间);
意向。额外(“标题”,标题);
意图。额外(“说明”,说明);
intent.putExtra(“事件位置”,位置);
intent.putExtra(“全天”,即全天);
//意向。额外(“rrule”,“FREQ=年度”);
}否则{
//冰淇淋三明治及以上
intent.setType(“vnd.android.cursor.item/event”);
intent.putExtra(CalendarContract.EXTRA\u EVENT\u BEGIN\u TIME,startTime);
intent.putExtra(CalendarContract.EXTRA\u EVENT\u END\u TIME,endTime);
意向。额外(事件。标题,标题);
intent.putExtra(Events.ACCESS\u LEVEL,Events.ACCESS\u PRIVATE);
intent.putExtra(CalendarContract.EXTRA\u EVENT\u ALL\u DAY,isAllDay);
intent.putExtra(Events.DESCRIPTION,DESCRIPTION);
intent.putExtra(Events.EVENT_位置,位置);
//intent.putExtra(Events.RRULE,“FREQ=DAILY;COUNT=10”)
}
试一试{
背景。开始触觉(意图);
返回true;
}捕获(例外e){
返回false;
}
}
}
要打开日历应用程序,请参阅《意向视图指南》谢谢您的回复。你能详细说明我如何在三星S3中解决这个问题吗?@BorntoWin我添加了一个示例,演示如何将事件添加到日历中,但从你的帖子中不清楚这是否是你想要的。如果你想打开日历应用程序,那么你就没有运气了。你可以像我一样,在它周围放置一个try-catch块,在应用程序不在手机上时通知用户。。。