GCM SERVICE_NOT_AVAILABE on the cellular network only

My friend and I are developing an Android application and implementing everything that is needed for GCM. On my device (Nexus 4), registration and reception of messages work fine through WiFi and cellular network. But if my friend tries to register his device (Xperia Z), he crashes through the cellular network, and he gets the SERVICE_NOT_AVAILABLE error. Through Wi-Fi, registering and receiving messages work fine with his device. If he registers his device on WiFi and then switches to cellular data, he will not receive any message!

We do not have enough devices for testing if this is a problem with its device or a problem in our application, so we hope you can help us. Here are some files of our project, if you need more information, I will add them later.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.mypackage.vorlesungsplan.app"
    android:versionCode="0010201"
    android:versionName="1.2.1 (Raw Potato)" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
    <uses-permission android:name="android.permission.GET_TASKS"/>
    <permission android:name="de.mypackage.vorlesungsplan.app.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="de.mypackage.vorlesungsplan.app.C2D_MESSAGE" />
    <supports-screens android:normalScreens="true" android:xlargeScreens="true" android:largeScreens="true" android:smallScreens="false"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:allowBackup="false" >
        <activity
            android:name="MainActivity"
            android:label="@string/title_activity_startup" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="SettingsActivity" android:label="Einstellungen" android:screenOrientation="portrait"></activity>
        <activity android:name="InfoHelpActivity" android:screenOrientation="portrait"></activity>
        <activity android:name="LunchActivity" android:screenOrientation="portrait"></activity>
        <meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version"/>

        <receiver
            android:name=".io.GCMBroadcastReceiver"
            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="de.mypackage.vorlesungsplan.app" />
            </intent-filter>
        </receiver>
        <service android:name=".io.GCMIntentService" />
    </application>

</manifest>

The register () method runs in the background, as the documentation does. Therefore, we used a regular stream instead of AsyncTask, but I do not think that this can cause a problem. The following class extends the Thread class:

RegisterServerOperation.java

public void run() {
    ...

    if(checkPlayServices()) {
        Logbook.d("Device is GCM capable");

        // Hole die regId des Geräts oder erzeuge eine neue
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(activity);
        String regId = Settings.getInstance(activity).getSetting("regId");

        if (regId == null || regId.isEmpty()) {
            regId = gcm.register(SENDER_ID);
            Settings.getInstance(activity).setSetting("regId", regId);
        }

        Logbook.d("Registration id for this device is: "+regId);
    } else {
        throw new Exception("REGISTRATION_FAILED");
    }

    ...
}

checkPlayServices() Google , "Device is GCM able" logcat. Settings - , Logbook - android.util.Log. DDMS:

traffic caputer with ddms

http-, . , . , gcm.register(...), .

google_play_services_lib:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="google_play_services_version">4132500</integer>
</resources>

Google Play, , ( 4.1.32). Android - 4,3, Sony. Nexus 4 CM 11 ( Android 4.4.2).

, Wi-Fi, . , , .

, - ,

+3

All Articles