I am new to firebase, I have a login screen. Post successful login, i would like to invoke the getToken method cause along with the Token i am also saving User loginid in centralised server. Hence after login i am calling these two lines.
FirebaseMessaging.getInstance().subscribeToTopic("test");
FirebaseInstanceId.getInstance().getToken();
My services is as follows
public class FirebaseInstanceIDService extends FirebaseInstanceIdService {
public static String busid;
@Override
public void onTokenRefresh() {
String token = FirebaseInstanceId.getInstance().getToken();
registerToken(token);
}
private void registerToken(String token) {
OkHttpClient client = new OkHttpClient();
business_login_id=Lib.GetPref(FirebaseInstanceIDService.this, "KEY_USER_ID", "");
RequestBody body = new FormBody.Builder()
.add("token",token)
.add("business_login_id", business_login_id)
.build();
Lib.Debug("Calling URL with body "+body.toString());
Request request = new Request.Builder()
.url("http://mywebsite.com/gcm/register.php")
.post(body)
.build();
try {
client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
}
}
My question is : Why Service FirebaseInstanceIDService is executing irrespective of Post Login screen and creating the Token id instantly for the app (in my case business_login_id is null).
At this time my user id is not logged in yet. Is there any way to control exactly POST login with the right credential create the Token NOW?