Firebase onMessageReceived not called when app in background

前端 未结 26 3317
粉色の甜心
粉色の甜心 2020-11-22 02:32

I\'m working with Firebase and testing sending notifications to my app from my server while the app is in the background. The notification is sent successfully, it even appe

26条回答
  •  感动是毒
    2020-11-22 03:01

    When message is received and your app is in background the notification is sent to the extras intent of the main activity.

    You can check the extra value in the oncreate() or onresume() function of the main activity.

    You can check for the fields like data, table etc ( the one specified in the notification)

    for example I sent using data as the key

    public void onResume(){
        super.onResume();
        if (getIntent().getStringExtra("data")!=null){
                fromnotification=true;
                Intent i = new Intent(MainActivity.this, Activity2.class);
                i.putExtra("notification","notification");
                startActivity(i);
            }
    
    }
    

提交回复
热议问题