让用户启用/禁用解析推送通知 [英] Let user enable/disable Push Notifications in Parse

查看:170
本文介绍了让用户启用/禁用解析推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用来自解析推送通知的Andr​​oid应用程序。在我的设置菜单我想有一个选项来启用/禁用推送通知,但我不能找到一种方法使用解析库来做到这一点。我在网上找到的所有方式似乎是使用现在去precated方法。

I'm developing an Android app that uses Push Notifications from Parse. On my settings menu I want to have an option to enable/disable push notifications but I can't find a way to do it using the parse library. All the ways I found online seem to be using methods that are now deprecated.

我不使用渠道,我只是叫Parse.initialize启动应用程序时。

I'm not using channels, I just call Parse.initialize when starting the app.

你知道我怎么能做到这一点?为了澄清我只需要知道如何使设备忽略收到的通知。

Do you know how I can achieve this? To clarify I just need to know how to make the device ignore incoming notifications.

问候

推荐答案

好吧,我摸索出了解决方案。我所要做的就是实现自己的接收器,取代解析的。

Ok, I've worked out a solution. What I had to do was implement my own Receiver that replaces Parse's.

public class MyCustomReceiver extends ParsePushBroadcastReceiver {

   @Override
   public void onReceive(Context context, Intent intent) {
       super.onReceive(context,intent);
   }
}

然后在的Andr​​oidManifest.xml 替换这样的:

<receiver
        android:name="com.parse.ParsePushBroadcastReceiver"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.parse.push.intent.RECEIVE" />
            <action android:name="com.parse.push.intent.DELETE" />
            <action android:name="com.parse.push.intent.OPEN" />
        </intent-filter>
</receiver>

本(把你的包名):

with this (put your package name) :

<receiver
        android:name="your.package.name.MyCustomReceiver"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.example.UPDATE_STATUS" />
            <action android:name="com.parse.push.intent.RECEIVE" />
            <action android:name="com.parse.push.intent.DELETE" />
            <action android:name="com.parse.push.intent.OPEN" />
        </intent-filter>
</receiver>

然后重写你的onReceive请你,比如说,我所做的就是:

Then rewrite your onReceive as you please, for instance, what I did was:

@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (!sharedPrefs.contains("NOTIF") || sharedPrefs.getBoolean("NOTIF", false))
        super.onReceive(context,intent);
}

变量 NOTIF 共享preferences说,如果用户想要接收通知与否。

The variable NOTIF in SharedPreferences says if that user wants to receive notifications or not.

这篇关于让用户启用/禁用解析推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆