1

カレンダーにイベントを挿入しようとしていますが、Android4以降とAndroid2.2で完全に機能しますが、Android 2.3でアプリを実行すると、次のように強制的に閉じます。

処理するアクティビティが見つかりません

Intent { act=android.intent.action.INSERT dat=content://com.android.calendar/events (has extras) }

ここにコードを示します:

 int currentapiVersion = android.os.Build.VERSION.SDK_INT;
            Uri u;
            if (currentapiVersion > android.os.Build.VERSION_CODES.FROYO){
                u = Uri.parse("content://com.android.calendar/events");
            } else{
                u = Uri.parse("content://calendar/events");
            }

            Intent intent = new Intent(Intent.ACTION_INSERT)
                    .setData(u)
                    .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, begin.getTimeInMillis())
                    .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end.getTimeInMillis())
                    .putExtra(Events.TITLE, title)
                    .putExtra(Events.DESCRIPTION, description)
                    .putExtra(Events.EVENT_LOCATION, getString(R.string.lugar)+ ": "+lugar)                     
                    .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);

                    String dest = new String();
                    for(int k=0;k<destinatarios.length;k++){
                        if(dest.equals("")){
                            dest = destinatarios[k];
                        }else{
                            dest += ","+destinatarios[k];
                        }

                    }
                    intent.putExtra(Intent.EXTRA_EMAIL, dest);

            startActivity(intent);

logcatを表示します:

11-28 12:13:06.113: E/AndroidRuntime(350): FATAL EXCEPTION: main
11-28 12:13:06.113: E/AndroidRuntime(350): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT dat=content://com.android.calendar/events (has extras) }
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.app.Activity.startActivityForResult(Activity.java:2827)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.app.Activity.startActivity(Activity.java:2933)
11-28 12:13:06.113: E/AndroidRuntime(350):  at com.moya.gestor.futbol.EventList.onContextItemSelected(EventList.java:283)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.app.Activity.onMenuItemSelected(Activity.java:2209)
11-28 12:13:06.113: E/AndroidRuntime(350):  at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2785)
11-28 12:13:06.113: E/AndroidRuntime(350):  at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
11-28 12:13:06.113: E/AndroidRuntime(350):  at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
11-28 12:13:06.113: E/AndroidRuntime(350):  at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:137)
11-28 12:13:06.113: E/AndroidRuntime(350):  at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:873)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.widget.ListView.performItemClick(ListView.java:3513)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.os.Handler.handleCallback(Handler.java:587)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.os.Looper.loop(Looper.java:123)
11-28 12:13:06.113: E/AndroidRuntime(350):  at android.app.ActivityThread.main(ActivityThread.java:3683)
11-28 12:13:06.113: E/AndroidRuntime(350):  at java.lang.reflect.Method.invokeNative(Native Method)
11-28 12:13:06.113: E/AndroidRuntime(350):  at java.lang.reflect.Method.invoke(Method.java:507)
11-28 12:13:06.113: E/AndroidRuntime(350):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-28 12:13:06.113: E/AndroidRuntime(350):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-28 12:13:06.113: E/AndroidRuntime(350):  at dalvik.system.NativeStart.main(Native Method)

ありがとう。

4

1 に答える 1

1

このメソッドを試して、異なるOSバージョンのイベントURIを取得してください

@TargetApi(14)
private String getCalendarUriBase(Activity act) {

    String calendarUriBase = null;
    Uri calendars = Uri.parse("content://calendar/calendars");
    Cursor managedCursor = null;
    try {
        managedCursor = act.managedQuery(calendars, null, null, null, null);
    } catch (Exception e) {
    }
    if (managedCursor != null) {
        calendarUriBase = "content://calendar/";
    } else {
        calendars = Uri.parse("content://com.android.calendar/calendars");
        try {
            managedCursor = act.managedQuery(calendars, null, null, null, null);
        } catch (Exception e) {
        }
        if (managedCursor != null) {
            calendarUriBase = "content://com.android.calendar/";
        }
    }
    return calendarUriBase;
}

URIはバージョンごとに異なるため、特定のバージョンのフィールド名を使用できます。CalendarContractは4.0バージョンから利用可能でした

ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
Uri EVENTS_URI = null;
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
        values.put(CalendarContract.Events.DTSTART, starttime);
        values.put(CalendarContract.Events.DTEND, endtime);
        values.put(CalendarContract.Events.TITLE, eventName);
        values.put(CalendarContract.Events.EVENT_LOCATION, eventLocation);
        values.put(CalendarContract.Events.DESCRIPTION, eventName);
        values.put(CalendarContract.Events.CALENDAR_ID, 1);
        values.put(CalendarContract.Events.HAS_ALARM,1);
        values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
        values.put(CalendarContract.Events.ALL_DAY, 0);
        values.put(CalendarContract.Events.HAS_ALARM, 1);
        values.put(CalendarContract.Events.ACCESS_LEVEL, CalendarContract.Events.ACCESS_DEFAULT);

        EVENTS_URI = CalendarContract.Events.CONTENT_URI;
    }
    else{
        EVENTS_URI = Uri.parse(getCalendarUriBase(getInstance()) + "events");

        values.put("calendar_id", 1);
        values.put("title", eventName);
        values.put("allDay", 0);
        values.put("dtstart", starttime);
        values.put("dtend", endtime);
        values.put("description", eventName);
        values.put("visibility", 0);
        values.put("hasAlarm", 1);
        values.put("eventLocation", eventLocation);
        values.put("eventTimezone", TimeZone.getDefault().getID());
    }
//      Log.e("check", EVENTS_URI.toString());

cr.insert(EVENTS_URI, values);
于 2012-11-28T13:02:43.067 に答える