我正在使用以下教程在我的Android应用程序中设置Google Cloud Messaging来推送通知:
http://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/remote_notifications_in_android/当我尝试在MainActivity
类的OnCreate
方法中注册我的应用程序时,它不返回registration_id
或error
。
null
。下面是我的应用程序的代码片段:
Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
intent.SetPackage("com.google.android.gsf");
intent.PutExtra("app", PendingIntent.GetBroadcast(Application.Context, 0, new Intent(), 0));
intent.PutExtra("sender", AndroidUserPreferences.GoogleCloudMessagingSenderId);
Application.Context.StartService(intent);
我需要检查什么才能让我的应用程序注册以接收Google Cloud Messaging通知?
编辑# 1:
在链接文档的注册Google Cloud Messaging部分下,有以下用于检索regsitration_id
的代码片段:
string registrationId = intent.GetStringExtra("registration_id");
我还没有对HandleRegistration
方法做任何事情,因为我还没有得到注册过程的工作。
我还没有对handlerregistration方法做任何事情因为我还没有让注册程序工作。
HandleRegistration
在你的应用程序收到GCM的注册响应时被调用。
因此,你应该得到注册ID在HandleRegistration
,所以我不确定你把string registrationId = intent.GetStringExtra("registration_id");
行,但你可能把它放在错误的地方。