2013-02-04 11 views
8

これは以前このフォーラムで尋ねられたことは知っていますが、私がしたいのはカレンダーにイベントを挿入することです。デバイスにはいくつかのカレンダーアプリケーションがあるので、ユーザーがマップアプリケーションを使用して場所を表示しようとしたときと同じように、カレンダーアプリケーションに新しいイベントを含めるかどうかを選択できますgoogleマップ、インターネット、...)。このため、インテントを使用する必要があります。インテントを使用してイベントをカレンダーに挿入する

私は、インテントを使用してカレンダーに新しいイベントを挿入することは、SDKのバージョンが14以上のデバイスでのみ許可されていることを認識しています。デバイスのAPIレベルは15であるため、カレンダーAPIがサポートされています。

02-04 17:55:23.957: E/AndroidRuntime(3781): FATAL EXCEPTION: main 
02-04 17:55:23.957: E/AndroidRuntime(3781): java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.applicat.meuchedet/com.applicat.meuchedet.MainScreenActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT dat=content://com.android.calendar/events (has extras) } 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.ActivityThread.access$600(ActivityThread.java:127) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.os.Handler.dispatchMessage(Handler.java:99) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.os.Looper.loop(Looper.java:137) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.ActivityThread.main(ActivityThread.java:4507) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at java.lang.reflect.Method.invoke(Method.java:511) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at dalvik.system.NativeStart.main(Native Method) 
02-04 17:55:23.957: E/AndroidRuntime(3781): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT dat=content://com.android.calendar/events (has extras) } 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1535) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1387) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.Activity.startActivityForResult(Activity.java:3190) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at com.applicat.meuchedet.Screen.startActivity(Screen.java:433) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at com.applicat.meuchedet.CalendarAppointmentScheduler.writeAppointmentToCalendar(CalendarAppointmentScheduler.java:137) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at com.applicat.meuchedet.MainScreenActivity.onCreate(MainScreenActivity.java:258) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.Activity.performCreate(Activity.java:4465) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932) 
02-04 17:55:23.957: E/AndroidRuntime(3781):  ... 11 more 

私が間違っているの何を:私はこの例外を取得

Intent calendarIntent = new Intent(Intent.ACTION_INSERT); 
calendarIntent.setData(Events.CONTENT_URI); 
calendarIntent.putExtra(Events.TITLE, "title"); 
calendarIntent.putExtra(Events.EVENT_LOCATION, "address"); 
Calendar cal = Calendar.getInstance(); 
cal.set(Calendar.DAY_OF_MONTH, 1); 
cal.set(Calendar.MONTH, 0); 
cal.set(Calendar.YEAR, 2013); 
cal.set(Calendar.HOUR_OF_DAY, 20); 
cal.set(Calendar.MINUTE, 0); 
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, cal.getTime().getTime()); 
cal.set(Calendar.HOUR_OF_DAY, 20); 
cal.set(Calendar.MINUTE, 30); 
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, cal.getTime().getTime()); 
ctx.startActivity(calendarIntent); 

は、ここに私のコードですか?

ありがとう

+0

のようなイベントを挿入?このエラーは、意図を処理するものが存在しないことを示しています。 – BoredAndroidDeveloper

答えて

11

すべての活動は、あなたの行動を扱うことができないので、あなたはActivityNotFoundExceptionをつかまえました。代わりにIntent.ACTION_INSERTを使用して

は次のように実行しよう:

Intent intent = new Intent(Intent.ACTION_EDIT); 
intent.setType("vnd.android.cursor.item/event"); 
intent.putExtra(Events.TITLE, strTitle); 
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, 
        startDateMillis); 
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, 
        endDateMillis); 
intent.putExtra(Events.ALL_DAY, false);// periodicity 
      intent.putExtra(Events.DESCRIPTION,strDescription)); 

あなたが他の属性のための開発者向けドキュメントをチェックインすることができます。

+0

私はYvanがこれを見て正しい方向に向いていると思います:http://stackoverflow.com/questions/9926830/error-inserting-event-into-calendar-with-intent明らかに、一部の電話機はACTION_INSERTを尊重しません。代わりにACTION_EDITが必要です。彼が持っているsetType行を使う必要はないと思っていますが、間違っている可能性があります – BoredAndroidDeveloper

+0

私はいつもYvanの方法を使っています。 – psykhi

+0

ありがとう!それは私のために働く。おそらくsetTypeコード行を使用する必要があるのでしょうか? – shai

0

カレンダーアプリがインストールされています。この

Calendar beginTime = Calendar.getInstance(); 
beginTime.set(2012, 0, 19, 7, 30); 
Calendar endTime = Calendar.getInstance(); 
endTime.set(2012, 0, 19, 8, 30); 
Intent intent = new Intent(Intent.ACTION_INSERT) 
    .setData(Events.CONTENT_URI) 
    .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, 
beginTime.getTimeInMillis()) 
    .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, 
endTime.getTimeInMillis()) 
    .putExtra(Events.TITLE, "Yoga") 
    .putExtra(Events.DESCRIPTION, "Group class") 
    .putExtra(Events.EVENT_LOCATION, "The gym") 
    .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY) 
    .putExtra(Intent.EXTRA_EMAIL, "[email protected],[email protected]"); 
startActivity(intent); 
関連する問題