Skip to content Skip to sidebar Skip to footer

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.

publicclassMyCustomReceiverextendsParsePushBroadcastReceiver {

   @OverridepublicvoidonReceive(Context context, Intent intent) {
       super.onReceive(context,intent);
   }
}

Then in AndroidManifest.xml replace this :

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

with this (put your package name) :

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

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

@OverridepublicvoidonReceive(Context context, Intent intent) {
    SharedPreferencessharedPrefs= 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"