0

在我的应用程序中,我使用以下代码在 DayView 上打开标准 android 日历:

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

这曾经可以很好地工作 - 在大多数手机上仍然可以正常工作。但是,昨天在一部手机(Android 2.3 - CM7)上,我开始收到此错误(为便于阅读而添加了换行符):

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

日志猫的完整错误如下:

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

我有两个问题:(1)它为什么突然坏了?它之前肯定在这款手机上工作过(这是我的主要手机);(2) 我该如何解决?

编辑只是补充一点,相同的代码在我拥有的另一部手机(HTC Desire X)上仍然可以正常工作。

4

2 回答 2

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.

于 2012-12-22T01:03:19.377 回答
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"/>
于 2012-12-21T09:45:07.083 回答