你必須認識到,你不能指望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;
}
}
}
感謝您的回覆。您能否詳細說明我如何在三星S3中解決這個問題? – 2013-02-27 06:42:17
@BorntoWin我已經添加了一個演示如何將事件添加到日曆的示例,但是如果這是您要查找的內容,則不清楚您的帖子。如果你想打開日曆應用程序,那麼你沒有運氣。你可以像我一樣做,並在其周圍放置一個try catch塊,在應用程序不在電話中時通知用戶... – Warpzit 2013-02-27 08:58:51