Android:InstanceID deleteToken Scope

时间:2015-06-12 11:00:22

标签: android google-cloud-messaging

我正在应用中实施Google Cloud Messaging。首先我使用InstanceID获取令牌,下一步是在我的服务器中注册设备,然后我得到一个HttpResponse。根据此响应,我想删除令牌并取消注册我的服务器中的设备。这是代码:

// [START register_for_gcm]
            InstanceID instanceID = InstanceID.getInstance(this);
            final String token = instanceID.getToken(manager.getSenderID(),GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            // [END get_token]
            Log.i(TAG, "GCM Registration Token: " + token);
            final Context context = ApplicationContextProvider.getContext();
            mRegisterTask = new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    HttpResponse response = manager.registerDevice(context, App.getInstance().getAppId(), token, null, null);
                    // At this point all attempts to register with the app server failed, so we need to unregister the device from GCM - the app will try to register again when
                    // it is restarted. Note that GCM will send an unregistered callback upon completion, but GCMIntentService.onUnregistered() will ignore it.
                    if (String.valueOf(response.getStatusLine().getStatusCode()).equals(200)==false){
                        instanceID.deleteToken(token, scope);
                        manager.unregister(context);
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    mRegisterTask = null;
                }
            };
            mRegisterTask.execute(null, null, null);

我正在寻找Android开发者Google Developers InstanceID,我找到了deleteToken(String authorizedEntity, String scope)。 authorizedEntity是在getToken()方法中获得的标记,但我不知道范围是什么。 有人能帮助我吗?

1 个答案:

答案 0 :(得分:1)

范围是&#34; GCM&#34;或常数

GoogleCloudMessaging.INSTANCE_ID_SCOPE

authorizedEntity是您的项目编号。这是reference link