尝试重新注销并注册您的设备。 在DemoActivity.java把
final String regId = GCMRegistrar.getRegistrationId(this);
GCMRegistrar.unregister(this);
然后,在第二次发射删除GCMRegistrar.unregister(this);
。
更新
通知您的应用程序:
创建类
public class DemoApplication extends Application {
private class NotifyReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "RECEIVE MESSAGE", Toast.LENGTH_SHORT).show();
}
}
private NotifyReceiver notifyReceiver = new NotifyReceiver();
@Override
public void onCreate() {
registerReceiver(notifyReceiver, new IntentFilter("GCM_MESSAGE"));
super.onCreate();
}
@Override
public void onTerminate() {
unregisterReceiver(notifyReceiver);
super.onTerminate();
}
}
然后把
<application
android:name=".DemoApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
在AndroidManifest.xml和
发送广播
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
String message = getString(R.string.gcm_message);
displayMessage(context, message);
context.sendBroadcast(new Intent("GCM_MESSAGE"));
// notifies user
generateNotification(context, message);
}
作为可选的情况下,你可以在清单,活动或前景服务
显示你的代码?从提供的链接下载它..我没有改变任何东西,除了我的项目ID ... – donparalias 2013-03-26 09:29:58
我很新的这个,但它可能需要一段时间,直到收到通知,以防应用程序不在前景? – 2013-03-26 09:34:02
你有消息说你的设备成功添加了,然后当你的Demo应用程序在后台没有收到通知?对? – Yahor10 2013-03-26 09:34:32