我正在爲Android開發聊天應用程序。但是,當試圖用GCM註冊時,我收到以下錯誤:Android - Android 6.0.1上的GCM錯誤「SERVICE_NOT_AVAILABLE」
04-02 16:59:29.793 29773-30031/purepush.group101.talktoday W/InstanceID/Rpc: Found 10010
04-02 16:59:29.920 29773-30031/purepush.group101.talktoday W/System.err: java.io.IOException: SERVICE_NOT_AVAILABLE
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.zzc.zzb(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.zzc.zza(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.InstanceID.zzc(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at com.google.android.gms.iid.InstanceID.getToken(Unknown Source)
04-02 16:59:29.922 29773-30031/purepush.group101.talktoday W/System.err: at purepush.group101.talktoday.LoginActivity$GetGCMTokenTask.doInBackground(LoginActivity.java:240)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at purepush.group101.talktoday.LoginActivity$GetGCMTokenTask.doInBackground(LoginActivity.java:211)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
04-02 16:59:29.923 29773-30031/purepush.group101.talktoday W/System.err: at java.lang.Thread.run(Thread.java:818)
04-02 16:59:29.958 29773-29773/purepush.group101.talktoday E/GcmReceiver: Failed to resolve target intent service, skipping classname enforcement
04-02 16:59:29.958 29773-29773/purepush.group101.talktoday E/GcmReceiver: Error while delivering the message: ServiceIntent not found.
我令牌使用下面的代碼獲得GCM:
InstanceID instanceID = InstanceID.getInstance(context);`
regToken = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="purepush.group101.talktoday">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="purepush.group101.talktoday.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="purepush.group101.talktoday.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity android:name=".ChatActivity" />
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="purepush.group101.talktoday" />
</intent-filter>
</receiver>
<service
android:name=".utils.GCMMessageListener"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>
</manifest>
Build.Gradle(應用模塊)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "21.1.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId 'purepush.group101.talktoday'
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'org.apache.httpcomponents:httpmime:4.5.2'
compile 'org.apache.httpcomponents:httpclient:4.5.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.android.gms:play-services:8.4.0'
}
現在有趣的是,這個錯誤只發生在我的Nexus 5運行6.0.1(Build:MMB29Q)上。我在運行5.1.1的同事的Samsung Note 4上測試了此應用程序,並且我能夠成功向GCM註冊他的設備。我收到此錯誤只使用GCM我的Nexus我們的應用程序的多個5.
任何幫助,將不勝感激
謝謝!
你有沒有在Gmail帳戶登錄您的Nexus 6獲取更多詳細信息?由於GCM需要電子郵件身份驗證才能註冊GCM服務器 – Kathi
它是Nexus 5並且是,我已登錄到我的Gmail帳戶。 –
有人可以指導我做什麼? –