Let User Enable/disable Push Notifications In Parse
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 d
Solution 1:
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);
}
}
Then in AndroidManifest.xml replace this :
<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:
@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.
Post a Comment for "Let User Enable/disable Push Notifications In Parse"