Android - GCMRegistrar.checkDevice() 的 UnSupportedOperation 异常

标签 android push-notification google-cloud-messaging android-5.0-lollipop unsupportedoperation

我正在开发一个 android 应用程序,我想在其中实现 GCM 功能。我能够实现并且它在 Android Kitkat 4.4 版本(在 Micromax 089 上测试)中运行良好。但不适用于Android Lolipop(Android 5.0)及以上版本的设备(如Lava Iris Fuel F1Moto x play)。

我用来验证设备依赖性和 list 权限的代码 fragment

GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
registerReceiver(mHandleMessageReceiver, new IntentFilter(
                DISPLAY_MESSAGE_ACTION));

应用在 GCMRegistrar.checkDevice(this);

处崩溃

Logcat 的屏幕截图

Screenshot of Logcat

通过一些研究,我发现了下面列出的一些应用程序可能崩溃的原因

  1. 该应用可能未针对 Google API。
  2. 可能未安装 Google Play 服务。
  3. 互联网可能不可用。
  4. 与自己的服务器的连接可能已断开。

即使我已经验证了上述所有情况,也无法解决问题。

请帮我找到解决方案。

最佳答案

您是否已将此代码添加到您的 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/

相关文章:

android - 蓝牙错误没有广告设备

android - 蓝牙 Le Gatt 找不到任何设备

javascript - Cordova视频方向问题android

ios - 推送通知到达时间

cocoa - NSServerNotificationCenter 和 Linux 服务器

ios - 我们可以确定 iOS 应用程序被用户强制退出吗

java - GCM onHandleIntent(Intent intent) 未被调用

android - 在 Android 中发布和调试应用程序版本。两个证书

Android GCM 转换监控

php - 谷歌云消息错误 500(内部服务器错误)