我想将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: _ ...
基于Google官方文档GoogleApiClient.OnConnectionFailedListener使用的错误代码。Google Play服务没有一个或多个必需的权限。客户端可以调用"startResolutionForResult(Activity,int)"来提示用户修复该问题。在活动返回"RESULT_OK"后,应成功进行进一步的连接尝试。
谷歌云消息(GCM)安卓客户端是在安卓设备上运行的客户端应用程序。我们建议您将GoogleCloudMessaging API和Android Studio与Gradle一起使用。
运行GCM安卓客户端是有要求的,GCM实现需要客户端实现和服务器实现。有关GCM android客户端的更多详细信息,请查看以下内容:https://developers.google.com/cloud-messaging/android/start