Firebase console: How to specify click_action for notifications

后端 未结 4 2095
耶瑟儿~
耶瑟儿~ 2020-12-01 01:48

I implemented Firebase and testing the Firebase notifications. When the app is in the foreground I don\'t have problems, I implemented a service that extends FirebaseMes

4条回答
  •  暖寄归人
    2020-12-01 02:20

    This question is 2 years old. But is still relevant. This is how you could do it with the firebase console (without `click_action).

    When your app is in background onMessageReceived will not be called. But when you get a notification while your app is in background, you will get an Intent along with the custom data you specify in the firebase console.

    So when the user taps the notification the intent will then be executed to open your launcher activity. You can check for the data by getIntent().hasExtra("key") in your launcher activity. Where the "key" is whatever key you specify in the console.

    Check if you have that "key" then, you can make another Intent and call startActivity

    Here is an implementation of mine,

    On my SplashActivity > OnCreate (This method Looks best if you have a splash screen as the launcher activity):

    if (getIntent().hasExtra("key")){
    
          Intent intent = new Intent(this, TargetActivity.class);
          startActivity(intent);
          finish();
    
    } else {
          startActivity(new Intent(this, MainActivity.class));
          finish();
    }
    

    This will just start the TargetActivity. You can add any functionality to this as per your wish :)

提交回复
热议问题