问题描述
我是pretty新的Java编程和一般节目。现在我决定把我自己的应用程序,应该使用谷歌云消息。并不知我成功了,但是后来我意识到我的方法
I'm pretty new to programming in Java and generally programming. Right now I decided to make my own app that is supposed to utilize Google Cloud Messaging. And somehow I succeeded but then I realized I used method
String regid = gcm.register(PROJECT_NUMBER);
这是德precated,我现在应该使用令牌和InstanceIDs。所以,我想重写我的注册使用它,但我遇到了一个问题,InstanceID.getInstancer()。我仔细其次从文档的所有步骤并不知它仍然无法正常工作。
that is deprecated and I should now use tokens and InstanceIDs. So I tried rewriting my registration to use it but I encountered a problem with InstanceID.getInstancer(). I carefully followed all steps from documentation https://developers.google.com/instance-id/guides/android-implementation and somehow it still doesn't work.
String authorizedEntity = "79424738XXXX";
String scope = "GCM";
String token = InstanceID.getInstance().getToken(authorizedEntity,scope);
Android的工作室告诉我的错误是:
Android Studio tells me that error is:
的getInstance() - 的getInstance(语境)中的InstanceID不能应用于
0
在此先感谢!
推荐答案
有是在的
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
这篇关于Google云端通讯 - InstanceID.getInstance()中,从客户端登记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!