【发布时间】:2015-06-22 22:03:00
【问题描述】:
我正在实施 GCM,理论上有一个合理的要求,android 2.3:https://developers.google.com/cloud-messaging/android/client
问题是它在我的 Android 5.1 设备和 Android 4.4 设备上工作,但它在我的 Android 4.1 设备、LG 和华为......
我可以在 logcat 中看到这个错误:GooglePlayServices not available due to error 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 实现(在 google play services 起源之前,当 GCM 是一个名为 gcm.jar 的 .jar 文件时)在这些 4.1 设备上可以 100% 正常工作。
【问题讨论】:
-
每次我遇到 GCM 问题时,我都需要在清单/代码中应用修复后完全删除/卸载应用程序。如果您认为自己进行了正确的修改,请尝试这样做。
-
我试过了,不行...
标签: android push-notification google-cloud-messaging android-notifications android-notification-bar