I am using Firebase for push notifications in my Android app. But it is sending notification when the app is in the background.
How should I handle it so that Firebase does not send notification when notifications are disabled from inside the app?
I am using Firebase for push notifications in my Android app. But it is sending notification when the app is in the background.
How should I handle it so that Firebase does not send notification when notifications are disabled from inside the app?
Whenever you using notification-payload your app will always show a notification in background. So you might want to just using data-payload which if you sending the message from console it is not possible. So you need to have your own web server to send your message with only data-payload key to fcm server. After you do so you need to check wether your app is in foreground or background because your onMessageReceived()
will always trigger if you use data-payload independently. Here is the link show you how to check wether your app is in foreground or background.
Here is part answer regarding your question. If you store the data which indicate wether user disable notification in sharePereference or dataBase you need to get the value and put it in if statement inside your onMessageReceived()
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(appIsNotInForeGround){ //you will not want to show a notification if your app is running.
if(!isMuteNotificaition){ // Check wether your user mute the app
sendNotification(); //your custom notification builder.
}
}
}
Reference the link I just show you for appIsNotInForeGround
.