When the application is alive everything is running properly but when no activity is running I still get a notification with app_name and Body by firebase notification and opens MainActivity.
here is my MyFirebaseMessagingService class:-
I saw a similar question but it did not help me in my case.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(remoteMessage.getNotification()!=null){
if(DictionarySscWords.send_notifications) { //tried removing this condition but same result.
sendnoti(remoteMessage.getNotification().getBody());
}
}
}
private void sendnoti(String body) {
Intent i1=new Intent(this,MainActivity.class);
i1.putExtra("word", body);
i1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pi=PendingIntent.getActivity(this,0,i1,PendingIntent.FLAG_CANCEL_CURRENT);
Uri ns=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder nb=new NotificationCompat.Builder(this).setSmallIcon(R.drawable.heart)
.setContentTitle("Word Of the Day")
.setContentText(body).setSmallIcon(R.drawable.heart)
.setAutoCancel(true)
.setSound(ns)
.setContentIntent(pi);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,nb.build());
}
}
when Application is alive
when no activity is running
Also Tried to run through AVD but No error.
Am confused how notification is created without passing through this class as if this was called different value will be populated here.
thanks