0

I've tried everything to get PreferenceManagers default SharedPreferences into my FirebaseMessageService.onMessageReceived when the app is closed, but I just can't get it to work. I can't seem to find out why this isn't possible.

I want the user to be able to turn off notifications from my settings panel, where there's a switch for Receive notifications.

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
if (sharedPreferences.getBoolean("receive_notifications", true) == true) {
   notificationManager.notify(0, notifiBuilder.build());
}

It will use the default value of true, no matter what the setting is.

Everything works perfect if the user is in the app, but not when it's closed.

AL.
  • 36,815
  • 10
  • 142
  • 281
Jesper
  • 3,816
  • 2
  • 16
  • 24

1 Answers1

0

Use getApplicationContext() instead this.

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())