我对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() – “getInstance (Context) in InstanceID cannot be applIEd
to 0”@H_403_23@
提前致谢!
解决方法:
有一个工作示例在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是您的项目ID(79424738XXXX)
这是RegistrationIntentService.this
总结以上是内存溢出为你收集整理的Java-GoogleCloudMessaging-InstanceID.getInstance(),从客户端注册全部内容,希望文章能够帮你解决Java-GoogleCloudMessaging-InstanceID.getInstance(),从客户端注册所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)