GCM在2.3.6版本中无法接收消息,但在4.1.2版本中可以。

3
问题只存在于安卓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;
}

https://dev59.com/mG3Xa4cB1Zd3GeqPj-e6#14716868 - Nachi
使用新版本的GCM,它不起作用了!:( - user3019841
2个回答

0

检查Google Play服务版本号,有一个相当明确定义的方法来检查Google Play服务的可用性。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接