我对 Java 编程和一般编程还很陌生。现在我决定制作自己的应用程序,该应用程序应该利用 Google Cloud Messaging。不知怎的,我成功了,但后来我意识到我使用了方法
String regid = gcm.register(PROJECT_NUMBER);
这已被弃用,我现在应该使用令牌和 InstanceID。所以我尝试重写我的注册来使用它,但我遇到了 InstanceID.getInstancer() 的问题。我仔细遵循文档中的所有步骤https://developers.google.com/instance-id/guides/android-implementation 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(Context)
至 0"
提前致谢!
有一个工作示例位于https://developers.google.com/cloud-messaging/android/start 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
)
this
is the RegistrationIntentService.this
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)