android - 注销新的 Google Cloud Messaging

标签 android push-notification google-cloud-messaging

我正在使用新的谷歌云消息传递

(GoogleCloudMessaging gcm =
           GoogleCloudMessaging.getInstance (context);)

我正在按照这个示例进行操作,它非常好并且可以完美运行:

https://github.com/commonsguy/cw-omnibus/tree/master/Push/GCMClient2

通过这个例子,我可以在 GCM 中注册,但我尝试注销失败。

在文档中指出您应该使用以下 Intent :

com.google.android.c2dm.intent.UNREGISTER

并按如下方式使用它:

 Intent unregIntent = new Intent ("com.google.android.c2dm.intent.UNREGISTER");
     unregIntent.putExtra ("app", PendingIntent.getBroadcast (this, 0, new Intent (), 0));
     StartService (unregIntent);

不工作......

正如我所说,注册工作正常,但不知道如何取消注册。

我有做多的 Intent 吗?我做错了什么?

感谢任何帮助

感谢和问候

最佳答案

如果您使用新的 GoogleCloudMessaging 类,则不需要使用 com.google.android.c2dm.intent.UNREGISTER Intent 。只需使用 GoogleCloudMessaging.unregister() .

public void unregister ()

Unregister the application. Calling unregister() stops any messages from the server. This is a blocking call—you shouldn't call it from the UI thread. You should rarely (if ever) need to call this method. Not only is it expensive in terms of resources, but it invalidates your registration ID, which should never change unnecessarily. A better approach is to simply have your server stop sending messages. Only use unregister if you want your application to stop using GCM permanently, or you have a compelling reason to recycle your registration ID. Throws IOException if we can't connect to server to unregister.

关于android - 注销新的 Google Cloud Messaging,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17722504/

相关文章:

android - 如何实现Activity之间的回调机制

android - New Relic 不工作(gradle + android studio)

android - 具有自定义状态的自定义按钮

google-chrome - Google 推送通知 - DOMException : Registration failed - push service error

java - 在android中如何访问从Api返回的Gson对象而不返回空指针异常?

ios - 几秒钟后第一次推送通知消失

azure - MS Azure 仅向 10 台设备发送通知

Node.js XMPP 客户端通过 Heroku 实现无法连接

android - 如何在屏幕锁定时显示推送通知

android - 如何检查 Google Play 服务是否已从 android 中的代码启用/禁用