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.