gpt4 book ai didi

android - 注销新的 Google Cloud Messaging

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:28 25 4
gpt4 key购买 nike

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

(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com