【问题标题】:Cannot resolve symbol 'GCMBroadcastReceiver' in Android Studio无法在 Android Studio 中解析符号“GCMBroadcastReceiver”
【发布时间】:2014-06-24 10:34:45
【问题描述】:

我正在尝试在我的 Android 应用程序中使用 GoogleCloudMessaging (GCM) API 推送通知。

参考http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/http://developer.android.com/google/play-services/setup.html#Setup,我尝试在AndroidManifest.xml 中设置它们,但它给了我一些错误:

  • 无法解析符号“GCMBroadcastReceiver”
  • 无法解析符号“GCMIntentService”

这个块在应用标签中

    <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="com.zaqqle.disqover" />
        </intent-filter>
    </receiver>

    <service android:name=".GCMIntentService" />

我正在使用 Android Studio 以及我做了什么

  • 在 SDK 管理器中安装了 Google Play 服务并与 Gradle 同步
  • 在 build.gradle 中包含 compile 'com.google.android.gms:play-services:4.3.23'
  • 在 AndroidManifest.xml 中包含 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

您能帮我指出我遗漏的地方吗?感谢您的帮助!

【问题讨论】:

    标签: android push-notification google-cloud-messaging


    【解决方案1】:

    com.google.android.gcm.GCMBroadcastReceiver 是一个已弃用的类,您的项目中可能没有它。您应该实现自己的广播接收器。 GCMIntentService 是你应该实现的类。

    您正在使用旧教程,该教程使用已弃用的类,而不是使用 Google Play 服务库。您应该参考当前的official GCM demo app 以查看清单的外观以及项目中应该包含哪些类。

    【讨论】:

    • 非常感谢。你的官方演示链接救了我的命!
    • 太好了,也为我工作。我已经在谷歌上搜索了一段时间,最后我看到了你的“GCMIntentService 是一个你应该实现的类”
    • 是的,我认为它已正式从 SDK 中删除。
    猜你喜欢
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 2019-02-07
    • 2023-03-27
    • 2015-07-28
    相关资源
    最近更新 更多