Вы должны понимать, что вы не можете ожидать 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;
}
}
}
Спасибо за ответ. Можете ли вы рассказать, как я могу решить эту проблему в Samsung S3? –
@BorntoWin Я добавил пример, показывающий, как добавить событие в календарь, но это не ясно из вашего сообщения, если это то, что вы ищете. Если вы хотите открыть приложение календаря, вам не повезло. Вы можете сделать так, как я, и поместить блок catch try вокруг него, чтобы уведомить пользователя, когда приложение не на телефоне ... – Warpzit