Reputation: 188
I am developing a chat application for Android. But while trying to register with GCM, I am receiving the following error:
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.
I am obtaining GCM token using the following code:
InstanceID instanceID = InstanceID.getInstance(context);`
regToken = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
MANIFEST:
<?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 (App Module)
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'
}
Now the funny thing is, this error occurs only on my Nexus 5 running 6.0.1 (Build: MMB29Q). I tested this application on my colleague's Samsung Note 4 running 5.1.1 and I was able to successfully register his device with GCM. I am getting this error with multiple of our applications using GCM only my Nexus 5.
Any help on this would be appreciated
Thanks!
Upvotes: 2
Views: 2164
Reputation: 748
I have faced the same situation some days ago, it is not the problem of GCM it is the problem of our internet connection. see below points for more understanding
you phone is connected to wifi but there is no internet from wifi, try to google in browser, if it is working perfectly then you should try some more things, like checking play services in your device and many more.
your phone's data pack could have been over , it means that you are connected to internet , but you won't get any kind of data from it. this error can not be identified without checking connection to your server.
You can get additional details from this link
How to fix Google Cloud Messaging Registration error: SERVICE_NOT_AVAILABLE?
Upvotes: 1
Reputation: 188
Well, it turns out that my Google Play store wasn't working properly. I could view apps and install new ones but when I entered "My apps & games", it gave me the Check your connection and try again
error. So, I am posting this solution for anyone who might be having a similar problem since I spend 4-5 days looking for errors and trying different fixes.
Note: This is only for rooted users.
Steps:
etc
etc
, you'll see a file name hosts
hosts
file, you'll see 2 IP addresses. The second one will vary depending upon your location#
at the start of the 2nd IP Address. #
will change that line to a commentI recommend making a backup of the hosts file before editing.
Credits to "Ronny927": http://forum.xda-developers.com/showthread.php?t=2273994
Upvotes: 1
Reputation: 2252
Please check your "Nexus 5" clock, it should be exact, and try to change
buildToolsVersion "21.1.2"
to something like: buildToolsVersion "23.0.2"
=> i'm using this version and GCM working well with Android 6
Update:
I'm using this Method to register my GCM
public void getRegId() {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
}
regid = gcm.register(R.string.gcm_defaultSenderId);
msg = "Device registered, registration ID=" + regid;
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
System.out.println("Error---" + ex.getMessage());
}
return msg;
}
@Override
protected void onPostExecute(String msg) {
System.out.println("Registerid---" + regid);
}
}.execute(null, null, null);
}
please try it and let me know.
Upvotes: 1