0

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).

Aleks G
  • 56,435
  • 29
  • 168
  • 265

2 Answers2

1

(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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • While I'm accepting this answer based on its merit and content, it's worth noting that the app initially came from a VERY BIG company (think multi-billion multinational). This app still works fine on three other phones I've tested and various emulators. – Aleks G Jan 04 '13 at 14:36
  • @AleksG: "it's worth noting that the app initially came from a VERY BIG company (think multi-billion multinational)" -- so? They are welcome to acquire Google and force employees to export that activity and provide a documented and supported means of accessing it. Or, they are welcome to write their own calendar application, so as not to be dependent upon one they do not control. – CommonsWare Jan 04 '13 at 15:19
0

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"/>
Mariusz Chw
  • 364
  • 2
  • 19
  • Yes, I do. However in this case it's irrelevant, as you only need this permission to directly read calendar data, not to invoke it via intent. Note that it is still working fine on another phone. – Aleks G Dec 21 '12 at 09:48