首页 文章

除非删除SEND权限,否则不会收到GCM消息

提问于
浏览
1

为了正确实现GCM,应根据the official docs为接收器指定 com.google.android.c2dm.SEND 权限:

接收方应该要求com.google.android.c2dm.SEND权限,以便只有GCM框架可以向其发送消息 .

但是,当我添加该权限时,收到消息时会收到此错误 .

W / GTalkService(25224):[DataMsgMgr]广播意图回调:result = CANCELED forIntent

然后是这个错误:

W / ActivityManager(283):权限拒绝:从com.google.android广播Intent 由于接收者com.XXX.XXX/com.XXX.XXX.GcmBroadcastReceiver,.syncadapters.contacts需要com.google.android.c2dm.SEND .

如果我仅删除该权限,而不更改任何其他内容,则接收器正常工作,我可以处理该消息 .

这是AndroidManifest.xml中的接收器定义

<receiver
        android:name="com.XXX.XXXX.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="com.XXX.XXX" />
        </intent-filter>
    </receiver>

我在测试期间使用调试证书,以防可能相关 .

2 回答

  • 5

    尝试 com.google.android.c2dm.permission.SEND 而不是 com.google.android.c2dm.SEND ,例如:

    <receiver
      android:name="GCMBroadcastReceiverCompat"
      android:permission="com.google.android.c2dm.permission.SEND">
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
        <category android:name="com.commonsware.android.gcm.client"/>
      </intent-filter>
    </receiver>
    

    (来自this sample app

  • 1

    试试这个:

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    
    <receiver
            android:name="com.robustastudio.mateegy.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
    
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    
                <category android:name="com.robustastudio.mateegy" />
            </intent-filter>
        </receiver>
    

相关问题