GoogleCloudMessaging - InstanceID.getInstance(),从客户端注册 [英] GoogleCloudMessaging - InstanceID.getInstance(), registering from client

查看:28
本文介绍了GoogleCloudMessaging - InstanceID.getInstance(),从客户端注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Java 编程和一般编程非常陌生.现在我决定制作我自己的应用程序,该应用程序应该使用 Google Cloud Messaging.不知何故我成功了,但后来我意识到我使用了方法

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);

这已被弃用,我现在应该使用令牌和 InstanceID.所以我尝试重写我的注册来使用它,但我遇到了 InstanceID.getInstancer() 的问题.我仔细地遵循了文档 https://developers.google.com/instance- 中的所有步骤id/guides/android-implementation 不知何故它仍然不起作用.

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 Studio 告诉我错误是:

Android Studio tells me that error is:

getInstance() - "InstanceID 中的getInstance (Context) 不能应用到 0"

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)

gcm_defaultSenderId is your project id (79424738XXXX)

thisRegistrationIntentService.this

这篇关于GoogleCloudMessaging - InstanceID.getInstance(),从客户端注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆