L
L
loly2016-06-12 22:01:58
Android
loly, 2016-06-12 22:01:58

How to get an FCM token unambiguously? In what cases is it not available? In what cases is it reissued?

I don't know if I should ask all three questions in 1 "topic", but I'll try.
1) How to get an FCM token unambiguously?
In the current application, obtaining an FCM token is a prerequisite for its operation, so at the very beginning I try to get it using the command (this, by the way, is also a minus of this solution, is there a replacement for FCM if it is missing?)

String fcmToken = FirebaseInstanceId.getInstance().getToken();

First but. It takes some time to generate it (as they say in foreign sources - "usually less than 10 seconds, depending on the Internet, device load, etc."). Thus, I will have to start a thread that will check the presence of a token every N seconds, and if it is received, then continue the application, which seems to me ... well, wrong, although I don’t see any other way.
2) In what cases is it impossible to obtain it?
Second but. To create it, there are several conditions known to me - the presence of google-play-services on the device, as well as an Internet connection. Is this the final list or are there any other dependencies/conditions?
3) In what cases is it issued again?
The function responsible for getting a token in the service is called
@Override
public void onTokenRefresh() {}

The name of the function, to put it mildly, hints at the fact that a new FCM can be issued (and why even a whole service to get a token, FirebaseInstanceIdService ). In what cases can this happen? Perhaps the name of the function is misleading me?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question