【问题标题】:Error = Cannot resolve symbol GoogleCloudMessaging in Android错误 = 无法在 Android 中解析符号 GoogleCloudMessaging
【发布时间】:2015-09-04 05:41:13
【问题描述】:

我正在使用 android studio 1.2.1 并使用 GCM 处理推送通知服务 意向服务

“无法解决 GoogleCloudMessaging”

代码如下:

Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
Log.e("test recieve", "-----Catch");
if (!extras.isEmpty()) {
    if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
            .equals(messageType)) {
        sendNotification("Send error"+ extras.toString());
    } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
            .equals(messageType)) {
        sendNotification("Deleted messages on server: "
                + extras.toString());
    } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
            .equals(messageType)) {
        for (int i = 0; i < 3; i++) {
            Log.i(TAG,
                    "Working... " + (i + 1) + "/5 @ "
                            + SystemClock.elapsedRealtime());
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
        }
        Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());

        sendNotification(""+extras.get(Config.MESSAGE_KEY));
        Log.i(TAG, "Received: " + extras.toString());
    }
}
GCMBroadcastReceiver.completeWakefulIntent(intent);
}

** 这是我的 Build Gradle**

 apply plugin: 'com.android.application'
       android
       {
   compileSdkVersion 22
   buildToolsVersion '22.0.1'
   defaultConfig
        {
     applicationId "insidesoftwares.gcmpush"
      minSdkVersion 16
      targetSdkVersion 22
      versionCode 1
      versionName "1.0"
     }
     buildTypes
        {
        release
            {
          minifyEnabled false
 proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
    }
  }
   }
  dependencies {
  compile 'com.google.android.gms:play-services:7.5.0'
  compile project(path:':backend',configuration: 'android-endpoints')
  compile 'com.nineoldandroids:library:2.4.0'
  compile 'com.google.code.gson:gson:2.2.4'
  compile files('libs/gcm.jar')
   }

提前致谢

【问题讨论】:

  • 您在项目中添加了 google play services 库吗?
  • 是的,在库中添加了 google play 服务 jar
  • 请发布您的 build.gradle 文件
  • 尝试编译'com.google.android.gms:play-services:7.0.0'
  • 你添加了gcm.jar吗?

标签: android google-cloud-messaging android-intentservice


【解决方案1】:

请尝试将其添加到您的 gradle 文件中:

compile 'com.google.android.gms:play-services-gcm:7.0.0'

compile 'com.google.android.gms:play-services:+'

【讨论】:

    【解决方案2】:

    我最近在 gcm 上工作过,没有任何问题。使用this 方法。我得到的唯一一个是即使在获得注册令牌之后 gcm api 也给出了未注册的消息。它的解决方案是从设备上卸载您的应用,然后重新安装。

    【讨论】:

      【解决方案3】:

      试试

      compile 'com.google.android.gms:play-services:7.0.0'
      

      而不是

      compile 'com.google.android.gms:play-services:7.5.0'
      

      在您的 Build.gradle 文件中。

      【讨论】:

        猜你喜欢
        • 2013-05-13
        • 1970-01-01
        • 2023-03-03
        • 1970-01-01
        • 2022-08-07
        • 2019-07-29
        • 1970-01-01
        • 1970-01-01
        • 2015-03-03
        相关资源
        最近更新 更多