GCM defaultSenderID [英] GCM defaultSenderID

查看:251
本文介绍了GCM defaultSenderID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人请帮我理解下面代码中的gcm_defaultSenderId是什么(在RegistrationIntentService.java中的onHandleIntent中找到):

  InstanceID instanceID = InstanceID.getInstance(this); 
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE,null);
// [END get_token]
Log.i(TAG,GCM注​​册令牌:+令牌);

这是Google实施GCM应用程序的示例应用程序,它甚至不会编译在他们的应用中!我确定这是每个应用程序特定的内容。我已经将GCM API添加到我的应用程序,只是不知道这个字符串应该是什么!感谢!

解决方案

引用

  String authorizedEntity = PROJECT_ID ; // Google Developers Console的项目ID 
String scope =GCM; //例如使用GCM进行通信,但您可以使用任何
//网址安全字符,最大数量为1000,或
//您也可以将其保留为空。
String token = InstanceID.getInstance()。getToken(authorizedEntity,scope);

所以,您可以看到,第一个参数应该传递给 getToken ) authorizedEntity ,它应该是Google开发者的项目ID:)

即使GitHub中的项目具有该字符串,它也不会为您提供任何好处,因为此 authorizedEntity 对于每个应用程序都是唯一的。


Could somebody please help me understand what the gcm_defaultSenderId is in the following code (found in onHandleIntent in RegistrationIntentService.java):

InstanceID instanceID = InstanceID.getInstance(this);
            String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            // [END get_token]
            Log.i(TAG, "GCM Registration Token: " + token);

This is from the Google sample app for implementing GCM into your app, and it doesn't even compile in their app! I'm sure it's something specific to each app. I've already added the GCM API to my application, just don't know what this string is supposed to be! Thanks!

解决方案

Quoting THIS document, where you can find details about that implementation:

String authorizedEntity = PROJECT_ID; // Project id from Google Developers Console
String scope = "GCM"; // e.g. communicating using GCM, but you can use any
                      // URL-safe characters up to a maximum of 1000, or
                      // you can also leave it blank.
String token = InstanceID.getInstance().getToken(authorizedEntity,scope);

So as you can see, the first param you should pass to getToken() is the authorizedEntity, which should be your project id from Google Developers :)

Even if the project in GitHub had that string, it wouldn't server you any good, as this authorizedEntity is something unique for each app.

这篇关于GCM defaultSenderID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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