2015-09-04 117 views
0
Google雲端通訊

我使用過Android Studio 1.2.1使用GCM錯誤 給出intentservice錯誤=無法解析符號的Android

推送通知服務工作「無法解析Google雲端通訊」

這裏是代碼:

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); 
} 

**這是我的構建搖籃**

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') 
    } 

由於提前

+0

您是否在項目中添加了Google Play服務庫? – Rajesh

+0

是在庫中添加了谷歌播放服務jar –

+0

請發佈你的build.gradle文件 – Rajesh

回答

4

請嘗試在gradle這個文件中添加此:

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

OR

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

我已經在最近GCM工作,沒有問題。使用this方法。我得到的只有一個,即使在獲得註冊令牌後,gcm api也沒有註冊消息。其解決方案是從設備上卸載您的應用程序,然後重新安裝它。

0

嘗試

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

,而不是

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

在您的Build.gradle文件中。

相關問題