Domanda

In my app I use the following code to open standard android calendar on the DayView:

Intent intent2 = new Intent();
intent2.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.DayActivity"));
intent2.setAction("android.intent.action.MAIN");
intent2.addCategory("android.intent.category.LAUNCHER");
intent2.setFlags(0x10200000);
intent2.putExtra("beginTime", (new Time()).setJulianDay(reqDay));
intent2.putExtra("DETAIL_VIEW", true);
intent2.putExtra("DETAIL_VIEW_MODE", 2);
context.startActivity(intent2);

This used to work perfectly fine - and still is working perfectly fine on most handsets. However on one phone (Android 2.3 - CM7) yesterday I started receiving this error (line breaks added for readability):

Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
flg=0x10200000 cmp=com.android.calendar/.DayActivity (has extras) }
from ProcessRecord{407719a0 3244:com.lge.android.calendarwidget/10077}
(pid=3244, uid=10077) requires null

The full error from the log cat is below:

I/ActivityManager(  245): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.calendar/.DayActivity (has extras) } from pid 3244
W/ActivityManager(  245): Permission denied: checkComponentPermission() reqUid=10004
W/ActivityManager(  245): Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.calendar/.DayActivity (has extras) } from ProcessRecord{407719a0 3244:com.lge.android.calendarwidget/10077} (pid=3244, uid=10077) requires null
W/calw3   ( 3244): com.android.calendar not found, trying com.google.android.calendar
W/calw3   ( 3244): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.calendar/.DayActivity (has extras) } from ProcessRecord{407719a0 3244:com.lge.android.calendarwidget/10077} (pid=3244, uid=10077) requires null

Two questions I have: (1) Why did it break all of a sudden? It definitely worked on this phone before (this is my main phone); and (2) how can I fix it?

EDIT Just to add that this same code is still working perfectly fine on another phone I own (HTC Desire X).

È stato utile?

Soluzione

(1) Why did it break all of a sudden? It definitely worked on this phone before (this is my main phone)

That application was upgraded, perhaps as part of a firmware upgrade, and that activity is no longer exported.

(2) how can I fix it?

Delete the code. You cannot start a private (non-exported) activity. Perhaps consider using CalendarContract to roll your own version of this activity, if that API supports whatever that activity did.

You shouldn't have been invoking undocumented activities in this app in the first place, as there was no guarantee that the app would exist on all devices, or support that activity on all devices. Your current state of affairs is just another, concrete manifestation of this problem.

Altri suggerimenti

It's quite strange that everything was fine before, I have to ask, do you have this line in android manifest?:

 <uses-permission android:name="android.permission.READ_CALENDAR"/>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top