我正在开发一个 android 应用程序,我想在其中实现 GCM 功能。我能够实现并且它在 Android Kitkat 4.4 版本(在 Micromax 089 上测试)中运行良好。但不适用于Android Lolipop(Android 5.0)及以上版本的设备(如Lava Iris Fuel F1和Moto x play)。
我用来验证设备依赖性和 list 权限的代码 fragment
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
registerReceiver(mHandleMessageReceiver, new IntentFilter(
DISPLAY_MESSAGE_ACTION));
应用在 GCMRegistrar.checkDevice(this);
Logcat 的屏幕截图。
通过一些研究,我发现了下面列出的一些应用程序可能崩溃的原因
- 该应用可能未针对 Google API。
- 可能未安装 Google Play 服务。
- 互联网可能不可用。
- 与自己的服务器的连接可能已断开。
即使我已经验证了上述所有情况,也无法解决问题。
请帮我找到解决方案。
最佳答案
您是否已将此代码添加到您的 list 中?
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="<YOUR PACKAGE NAME>" />
</intent-filter>
</receiver>
顺便说一下,GCMRegistrar 已经过时了,我不推荐它。用这个 GCM Android
您可以尝试使用 Google Cloud Messaging库,而不是包含 GCMRegistrar 的已弃用库。这是因为某些设备的 Android 皮肤中没有此软件包 com.google.android.gsf,尤其是联想和摩托罗拉,这就是为什么您必须在 checkDevice() 上获得不受支持的异常
关于Android - GCMRegistrar.checkDevice() 的 UnSupportedOperation 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36574925/