What to use now that FirebaseInstanceId.getInstance().getToken() is deprecated

  • A+
Category:Languages

I would like to know what would be the correct way to get Firebase token for sending push notification now that getToken() is deprecated.

 


As documentation says :

This method was deprecated. In favour of getInstanceId().

Use getInstanceId(). It will return a Task with and InstanceIdResult. Like this:

 FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( context,  new OnSuccessListener<InstanceIdResult>() {                                     @Override                 public void onSuccess(InstanceIdResult instanceIdResult) {                       String deviceToken = instanceIdResult.getToken();                       // Do whatever you want with your token now                       // i.e. store it on SharedPreferences or DB                       // or directly send it to server                  } }); 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: