2

I am using Firebase Cloud Messaging and want to display a call. The firebase message is received successfully and the notification part works but i am unable to launch the ShowCallActivity from inside my FirebaseMessagingService when the application has been closed and is DEAD

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    if(remoteMessage.getNotification().getBody().equals("showcall")) {
            Log.e(TAG,"Want to start activity");
            Intent intent = new Intent(this,ShowCallActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            sendNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
        }
    }

}
// 

The notification is shown but it won't open the dead application.

Muddassir Ahmed
  • 506
  • 4
  • 15

2 Answers2

1

I order to make it work I had to use a data message and keep the "notification" key empty.

Example from firebase docs.

{
    "message":{
        "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
        "data":{
             "Nick" : "Mario",
             "body" : "great match!",
             "Room" : "PortugalVSDenmark"
        }
     }
}
Muddassir Ahmed
  • 506
  • 4
  • 15
1

I'm new in programming and finally found a little clue about this problem. The new version of android (MarshMallow) has a new restriction that restricts activity to be opened from the app when the app is dead. I can't explain much but you can read here https://developer.android.com/guide/components/activities/background-starts?authuser=1 Every intent works well if this permission is granted. You could check on any VOIP app like WhatsApp. the app already granted this permission without the user knowing. hope this help

Kevin Farel
  • 107
  • 1
  • 10