Firebase FCM token - When to send to server?

后端 未结 4 818
眼角桃花
眼角桃花 2020-12-31 04:19

Okay so I have an app which on first start takes you through a few welcoming slides, then takes you to a login/register page and then to MainActivity.

I

4条回答
  •  清歌不尽
    2020-12-31 04:41

    December 2020 update : Using the new Firebase SDK (21.0.0) you can get it by overriding onNewToken() method :

    @Override
    public void onNewToken(@NonNull String s) {
        super.onNewToken(s);
        sendRegistrationToServer(s);
    }
    

    Or by FirebaseInstallations.getInstance() within your scope :

    FirebaseInstallations.getInstance().getToken(false).addOnCompleteListener(new OnCompleteListener() {
              @Override
              public void onComplete(@NonNull Task task) {
                  if(!task.isSuccessful()){
                      return;
                  }
                  // Get new Instance ID token
                  String token = task.getResult().getToken();
    
              }
          });
    

提交回复
热议问题