GCM在2.3.6中没有收到消息,但在4.1.2中没有问题

时间:2014-01-29 10:11:19

标签: java android google-cloud-messaging

问题仅在于android 2.3.6。 使用4.x,没有任何问题,接收器没问题。 我收到了2.3.6的注册ID,但邮件从未收到过。

我的清单是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.arte.biluna”
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission
    android:name="net.arte.biluna.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="net.arte.biluna.permission.C2D_MESSAGE" />

<application
    android:name="net.arte.biluna.businesslogic.CosmoApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock.Light" >

    <!-- android:theme="@style/Theme.Sherlock" > -->
    <activity
        android:name="net.arte.biluna.SplashScreen"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        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="net.arte.biluna.GreatestActivity"
        android:screenOrientation="portrait" />
    <activity
        android:name="net.arte.biluna.LogInActivity"
        android:screenOrientation="portrait" />
    <activity
        android:name="net.arte.biluna.HomePage"
        android:screenOrientation="portrait" />
    <activity
        android:name="net.arte.biluna.LiveTourActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateHidden" />
    <activity
        android:name="net.arte.biluna.ChatActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateHidden" />
    <activity
        android:name="net.arte.biluna.ForYouActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateHidden" />
    <activity
        android:name="net.arte.biluna.StoreActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateHidden" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <service android:name="net.arte.biluna.GcmIntentService" />

    <receiver
        android:name="net.arte.biluna.GcmBroadcastReceiver"
        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="net.arte.biluna" />
        </intent-filter>
    </receiver>
</application>

我的接收者:

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(),
            GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
}
}

我的活动:

...
if (checkPlayServices()) {
            gcm = GoogleCloudMessaging.getInstance(this);
            regid = getRegistrationId(context);

            if (regid.equals("")) {
                registerInBackground();
            }

        }
...

private boolean checkPlayServices() {
    int resultCode = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                    PLAY_SERVICES_RESOLUTION_REQUEST).show();
        } else {
            finish();
        }
        return false;
    }
    return true;
}

2 个答案:

答案 0 :(得分:0)

检查Google Play服务版本号,并且有一种非常明确的方法可以检查Google Play服务的可用性

答案 1 :(得分:0)

使用google play的最新gcm版本非常易于实施,可以使用更长时间。

参见本教程。希望它可能有所帮助。

  

http://techlovejump.in/2013/11/android-push-notification-using-google-cloud-messaging-gcm-php-google-play-service-library/