我在一个应用程序中实现了Google消息传递。首先,我使用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);我正在寻找安卓开发者谷歌开发者InstanceID,然后我找到了deleteToken(String authorizedEntity, String scope)。authorizedEntity是在getToken()方法中获得的令牌,但我不知道作用域是什么。有人能帮我吗?
发布于 2015-06-13 15:25:34
https://stackoverflow.com/questions/30801447
复制相似问题