错误 = 无法解析 Android 中的符号 GoogleCloudMessaging
Error = Cannot resolve symbol GoogleCloudMessaging in Android
我正在使用 android studio 1.2.1 并使用 GCM 处理推送通知服务错误在中给出
意图服务
"Cannot Resolve 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);
}
** 这是我的版本 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')
}
提前致谢
我最近在做gcm,没问题。使用 this 方法。我得到的只有一个是在获得注册令牌后 gcm api 给出了未注册的消息。它的解决方案是从设备上卸载您的应用程序,然后重新安装。
请尝试将此添加到您的 gradle 文件中:
compile 'com.google.android.gms:play-services-gcm:7.0.0'
或
compile 'com.google.android.gms:play-services:+'
尝试
compile 'com.google.android.gms:play-services:7.0.0'
而不是
compile 'com.google.android.gms:play-services:7.5.0'
在您的 Build.gradle
文件中。
我正在使用 android studio 1.2.1 并使用 GCM 处理推送通知服务错误在中给出 意图服务
"Cannot Resolve 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);
}
** 这是我的版本 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')
}
提前致谢
我最近在做gcm,没问题。使用 this 方法。我得到的只有一个是在获得注册令牌后 gcm api 给出了未注册的消息。它的解决方案是从设备上卸载您的应用程序,然后重新安装。
请尝试将此添加到您的 gradle 文件中:
compile 'com.google.android.gms:play-services-gcm:7.0.0'
或
compile 'com.google.android.gms:play-services:+'
尝试
compile 'com.google.android.gms:play-services:7.0.0'
而不是
compile 'com.google.android.gms:play-services:7.5.0'
在您的 Build.gradle
文件中。