android - Parse.com 推送通知问题。取消订阅不起作用,仍在接收推送通知。(Android)

标签 android notifications parse-platform

我制作了一个使用 Parse.com 推送通知的应用程序。我有一个设置页面,您可以在其中启用/禁用推送通知。设置页面运行良好,它更改了使用的首选项,但推送通知不会停止。

这是我订阅/取消订阅的代码:

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
            pushNotificationsPreference = sharedPrefs.getBoolean("PUSH_NOTIFICATION_PREFERENCE", true);

            if (pushNotificationsPreference) {
                ParsePush.subscribeInBackground("Android", new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e != null) {
                            Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
                        } else {
                            Log.e("com.parse.push", "failed to subscribe for push" + e);
                        }
                    }
                });
            } else {
                ParsePush.unsubscribeInBackground("Android", new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e != null) {
                            Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
                        } else {
                            Log.e("com.parse.push", "failed to unsubscribe for push" + e);
                        }
                    }
                });

            }

如果“pushNotificationsPreference”为 false,它会调用方法“ParsePush.unsubscribeInBackground("Android", new SaveCallback()"),但它不会订阅,我仍在接收它们。

我上了 Parse.com,我只在“Android” channel 注册了。

我错过了什么吗?

最佳答案

只需添加

if (e == null) {
    ParseInstallation.getCurrentInstallation().saveInBackground();
}

进入 ParsePush.unsubscribeInBackground(...)done()

关于android - Parse.com 推送通知问题。取消订阅不起作用,仍在接收推送通知。(Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26816573/

相关文章:

ios - 为 NSDate 添加 24 小时

javascript - 连接到我的解析服务器返回 404

android - 在android中对Bundle的键值对进行排序

java - 使用 Intents 传递铃声数据

android - 在 Activity 可见时隐藏前台服务的通知

javascript - 我可以在特定时间发送 Web 通知吗?

ios - Swift Parse - 嵌套调用问题

android - 来自 SQLite 数据库的 XML 数组

android - 在 Android 中为 ArrayList 设置自定义适配器

mysql - 群组通知系统数据库设计