我尝试从 gcm.jar 更新以从 google-play-services.jar 获取 GCM。我正在使用与此处所示相同的代码。
我使用与更改客户端实现之前相同的服务器(node-gcm)。
我得到了registrationId,但是当我尝试发送通知时,没有调用GcmBroadcastReceiver.onReceive。(我在清单文件中有它)
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
/**
* Created with IntelliJ IDEA.
* User: Eran
* Date: 11/11/13
* Time: 00:43
* To change this template use File | Settings | File Templates.
*/
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("GcmBroadcastReceiver", intent.getDataString());
// 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);
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gamerlabs.high5poker"
android:versionCode="3"
android:versionName="3.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
>
</supports-screens>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.android.vending.BILLING" />
<permission android:name="com.gameralabs.high5poker.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.gameralabs.high5poker.permission.C2D_MESSAGE" />
<application
android:name="com.gameralabs.classes.HFApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true"
android:largeHeap="true"
android:debuggable="true"
>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
<activity android:name="com.facebook.LoginActivity"/>
<activity
android:name="com.gameralabs.high5poker.HFSplashActivity"
android:screenOrientation="landscape"
android:noHistory="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.gameralabs.high5poker.HFLoginActivity"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
</activity>
<activity
android:name="com.gameralabs.high5poker.HFLobbyActivity"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
</activity>
<activity
android:name="com.gameralabs.high5poker.HFGameActivity"
android:noHistory="true"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
</activity>
<activity android:name="com.gameralabs.high5poker.HFActivity"/>
<receiver
android:name="com.gameralabs.high5poker.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.gameralabs.high5poker" />
</intent-filter>
</receiver>
<service android:name="com.gameralabs.high5poker.GcmIntentService" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>
</manifest>
有什么帮助吗?