权限拒绝:getIntentSender()

时间:2011-06-23 09:26:55

标签: android android-widget android-pendingintent

我正在尝试在应用小部件提供商的onUpdate方法中为小部件设置待处理意图但是我在尝试设置待处理意图时不断获得权限拒绝:getIntentSender()。为简单起见,我已经将课程剥离了下来:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    final int N = appWidgetIds.length;
    Intent appIntent = new Intent(context,Main.class);
    PendingIntent pendingAppIntent = PendingIntent.getActivity(
            context, 0, appIntent, 0);

   super.onUpdate(context, appWidgetManager, appWidgetIds);
}

我得到了以下的堆栈跟踪:

06-23 10:18:45.270: ERROR/AndroidRuntime(6536): java.lang.RuntimeException: Unable to    start receiver com.distilledmedia.thejournal.widget.JournalAppWidgetProvider: java.lang.SecurityException: Permission Denial: getIntentSender() from pid=6536, uid=10062,   (need uid=-1) is not allowed to send as package com.distilledmedia.thejournal.client
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:1805)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.app.ActivityThread.access$2400(ActivityThread.java:117)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.os.Looper.loop(Looper.java:130)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at java.lang.reflect.Method.invokeNative(Native Method)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at  java.lang.reflect.Method.invoke(Method.java:507)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at dalvik.system.NativeStart.main(Native Method)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536): Caused by: java.lang.SecurityException: Permission Denial: getIntentSender() from pid=6536, uid=10062, (need uid=-1) is not allowed to send as package com.distilledmedia.thejournal.client
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.os.Parcel.readException(Parcel.java:1322)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.os.Parcel.readException(Parcel.java:1276)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.app.ActivityManagerProxy.getIntentSender(ActivityManagerNative.java:2254)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.app.PendingIntent.getActivity(PendingIntent.java:195)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at com.distilledmedia.thejournal.widget.JournalAppWidgetProvider.onUpdate(JournalAppWidgetProvider.java:41)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:61)
06-23 10:18:45.270: ERROR/AndroidRuntime(6536):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:1794)

这是清单中App Widget的条目:

<receiver android:name="com.distilledmedia.thejournal.widget.JournalAppWidgetProvider" >
    <intent-filter>
    <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>
    <meta-data  android:name="android.appwidget.provider"
                android:resource="@xml/journal_widget" />
</receiver>

主要活动的条目:

<activity android:name="com.distilledmedia.thejournal.client.Main"
              android:label="@string/app_name"
              android:configChanges="orientation" android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
 </activity>

可能是因为窗口小部件与主要活动位于不同的包中吗?

任何帮助非常感谢

1 个答案:

答案 0 :(得分:0)

我认为您的回答是thissnailer回答。