10
04-25 14:16:30.931: E/AndroidRuntime(6638): FATAL EXCEPTION: main
04-25 14:16:30.931: E/AndroidRuntime(6638): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {com.exclusive26.igale/com.exclusive26.igale.Push_Activity}: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } without permission com.google.android.c2dm.permission.RECEIVE
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2553)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2595)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.app.ActivityThread.access$2000(ActivityThread.java:121)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.os.Looper.loop(Looper.java:130)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.app.ActivityThread.main(ActivityThread.java:3701)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at java.lang.reflect.Method.invoke(Method.java:507)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at dalvik.system.NativeStart.main(Native Method)
04-25 14:16:30.931: E/AndroidRuntime(6638): Caused by: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } without permission com.google.android.c2dm.permission.RECEIVE
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.app.ContextImpl.startService(ContextImpl.java:867)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.content.ContextWrapper.startService(ContextWrapper.java:336)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at com.google.android.c2dm.C2DMessaging.register(C2DMessaging.java:54)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at com.exclusive26.igale.Push_Activity.register(Push_Activity.java:124)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at com.exclusive26.igale.Push_Activity.onActivityResult(Push_Activity.java:58)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.app.Activity.dispatchActivityResult(Activity.java:3908)
04-25 14:16:30.931: E/AndroidRuntime(6638):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2549)
04-25 14:16:30.931: E/AndroidRuntime(6638):     ... 11 more

意图确实在清单中具有适当的权限:

显现:

<permission
    android:name="com.exclusive26.igale.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.exclusive26.igale.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.exclusive26.igale.c2dm.permission.RECEIVE"/>
...
...
<activity android:name=".Push_Activity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
    </intent-filter>
</activity>
...
...
<service android:name=".C2DMReceiver" />

<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
    android:permission="com.google.android.c2dm.permission.SEND">

    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="com.exclusive26.igale" />
    </intent-filter>

    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION"/> 
        <category android:name="com.exclusive26.igale" />
    </intent-filter>
</receiver>

在 Push_Activity.java 中检查以下代码:

com.google.android.c2dm.C2DMessaging.register( this, com.exclusive26.igale.Config.C2DM_SENDER );

在 C2DMessaging.register 中正确发送的参数(Push_Activity 上下文和一些电子邮件地址 <-- 静态最终字符串):

public static void register(Context context,
        String senderId) {
    Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT);
    registrationIntent.setPackage(GSF_PACKAGE);
    registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,
            PendingIntent.getBroadcast(context, 0, new Intent(), 0));
    registrationIntent.putExtra(EXTRA_SENDER, senderId);
    context.startService(registrationIntent);
    // TODO: if intent not found, notification on need to have GSF
}

在 startService() 我得到了异常。没有 idia 如何解决这个问题。请阐明这个问题。非常感谢!

4

4 回答 4

13

仅供未来出现此错误的用户使用:清单文件应如下所示:

<permission
    android:name="YOUR_PACKAGE.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="YOUR_PACKAGE.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

代替

<permission
    android:name="YOUR_PACKAGE.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="YOUR_PACKAGE.permission.C2D_MESSAGE" />
<uses-permission android:name="YOUR_PACKAGE.permission.RECEIVE" />

我花了大约 5 个小时来找出我的项目出了什么问题 :)

于 2013-11-14T14:41:41.993 回答
2

也许我遗漏了一些东西,但错误显示“com.google.android.c2dm.permission.RECEIVE”并且清单包含“com.google.android.c2dm.permission.SEND”所以我看不到完美匹配。

于 2012-04-25T12:27:48.453 回答
1

代码是正确的。我创建了一个新项目,复制了代码,没有问题了

于 2012-04-29T12:42:53.480 回答
0

如果我们在 Activity Java 文件中错误地使用了某些资源的名称,也可能会出现此错误。我也遇到了同样的错误,但我还没有使用任何服务或权限。问题出在资源 ID 错误的 onCreate() 方法上。

于 2017-01-31T11:14:20.743 回答