[英]Let user enable/disable Push Notifications in Parse
I'm developing an Android app that uses Push Notifications from Parse. 我正在开发一个使用Parse中的Push Notifications的Android应用。 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.
我在网上找到的所有方法似乎都在使用现在不推荐使用的方法。
I'm not using channels, I just call Parse.initialize when starting the app. 我没有使用通道,我只是在启动应用程序时调用Parse.initialize。
Do you know how I can achieve this? 你知道我怎么能做到吗? To clarify I just need to know how to make the device ignore incoming notifications.
为了澄清,我只需要知道如何使设备忽略传入的通知即可。
Regards 问候
Ok, I've worked out a solution. 好的,我已经解决了。 What I had to do was implement my own Receiver that replaces Parse's.
我要做的是实现自己的Receiver来代替Parse的Receiver。
public class MyCustomReceiver extends ParsePushBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context,intent);
}
}
Then in AndroidManifest.xml replace this : 然后在AndroidManifest.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>
Then rewrite your onReceive as you please, for instance, what I did was: 然后根据需要重写onReceive,例如,我所做的是:
@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);
}
The variable NOTIF in SharedPreferences says if that user wants to receive notifications or not. SharedPreferences中的变量NOTIF表示该用户是否要接收通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.