由于Android 6上的权限,GCM 8.4.0连接失败

时间:2016-04-05 22:29:25

标签: java android google-cloud-messaging android-6.0-marshmallow

我想将GCM添加​​到我的应用程序并注册用户设备,但我有一个奇怪的问题:

W/GMPM: Service connection failed: ConnectionResult{statusCode=SERVICE_MISSING_PERMISSION, resolution=PendingIntent{c28038b: android.os.BinderProxy@6a00c68}, message=null}

设备无法注册,我无法获取注册令牌。我该如何解决这个问题?

我的清单文件权限:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="ir.makbn.mashfood.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="ir.makbn.mashfood.permission.C2D_MESSAGE"/>

和我的接收器类定义:

 <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        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="ir.makbn.mashfood.gcm" />
        </intent-filter>
    </receiver>
    <service
        android:name=".service.MyGcmListener"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

    <service
        android:name=".service.MyInstanceIDListener"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID" />
        </intent-filter>
    </service>

我的所有接收器类都与Google GCM示例中的相同,我使用的是GCM 8.4.0。

在我的共享偏好设置中,我发现com.google.android.gcm.measurement.prefs包含:

...name="health_monitor_value">1wc8487:service connection faild: _ ...

1 个答案:

答案 0 :(得分:1)

基于Official Google Documentation GoogleApiClient.OnConnectionFailedListener使用的错误代码。 Google Play服务没有一个或多个必需的权限。客户端可以致电'startResolutionForResult(Activity, int)'以提示用户解决问题。活动返回'RESULT_OK'后,进一步尝试连接应该会成功。

Google Cloud Messaging(GCM)Android客户端是在Android设备上运行的客户端应用。我们建议您使用GoogleCloudMessaging API和Android Studio with Gradle。

运行GCM Android客户端有要求,GCM实施需要客户端实现和服务器实现。有关GCM android客户端的更多详细信息,请查看:https://developers.google.com/cloud-messaging/android/start