我正在实施GCM,它有一个合理的要求,android 2.3:https://developers.google.com/cloud-messaging/android/client
问题是它在我的Android 5.1设备和Android 4.4设备上运行,但它在我的Android 4.1设备,LG和华为中无效....
我可以在logcat中看到此错误: GooglePlayServices由于错误2而无法使用
在上一个链接中,我可以看到:
如果您想支持4.4之前的KitKat设备,请添加以下内容 对接收者的意图过滤器声明的操作:
所以我添加了它,这是我在清单中添加的内容:
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- This app has permission to register and receive data message. -->
<!-- Creates a custom permission so only this app can receive its messages. NOTE: APP_PACKAGE.permission.C2D_MESSAGE -->
<permission android:name="com.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.permission.C2D_MESSAGE" />
<!-- BroadcastReceiver that will receive intents from GCM services and handle them to the custom IntentService. -->
<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="com.myapp" />
</intent-filter>
</receiver>
<service
android:name="com.myapp.util.notifications.GCMListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="com.myapp.util.notifications.CustomInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="com.myapp.util.notifications.RegistrationIntentService"
android:exported="false">
</service>
这非常令人沮丧,因为这两款设备都是Android 4.1,比Android 2.3更高。
在此之前,我使用GCM的旧实现(在谷歌播放服务起源之前,当GCM是名为gcm.jar的.jar文件时)在这些4.1设备上100%正常工作。
答案 0 :(得分:0)
在您正在测试的设备4.1中,首先您必须更新设备的Google Play服务..之后检查您的日志并显示日志以便我可以帮助您?