我对Java编程和一般的编程很陌生。现在,我决定制作自己的应用程序,该应用程序应该利用Google Cloud Messaging。我以某种方式成功了,但是后来我意识到我使用了方法
String regid = gcm.register(PROJECT_NUMBER);
已弃用,我现在应该使用令牌和InstanceID。因此,我尝试重写注册以使用它,但是我遇到了InstanceID.getInstancer()的问题。我仔细遵循了文档https://developers.google.com/instance-id/guides/android-implementation中的所有步骤,但仍然无法正常工作。
String authorizedEntity = "79424738XXXX";
String scope = "GCM";
String token = InstanceID.getInstance().getToken(authorizedEntity,scope);
Android Studio告诉我错误是:
getInstance()-“ InstanceID中的getInstance(上下文)不能应用于0”
提前致谢!
https://developers.google.com/cloud-messaging/android/start上有一个工作示例
git clone https://github.com/googlesamples/google-services.git
他们在那里 RegistrationIntentService.java
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
gcm_defaultSenderId
是您的专案编号(79424738XXXX
)
this
是个 RegistrationIntentService.this
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句