gpt4 book ai didi

java - GoogleCloudMessaging - InstanceID.getInstance(),从客户端注册

转载 作者:太空宇宙 更新时间:2023-11-03 13:19:29 25 4
gpt4 key购买 nike

我对 Java 编程和一般编程还很陌生。现在我决定制作我自己的应用程序,该应用程序应该使用谷歌云消息传递。不知何故我成功了,但后来我意识到我使用了方法

String regid = gcm.register(PROJECT_NUMBER);

已弃用,我现在应该使用 token 和 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"

提前致谢!

最佳答案

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)

thisRegistrationIntentService.this

关于java - GoogleCloudMessaging - InstanceID.getInstance(),从客户端注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30687052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com