java - android studio firebase gettoken id -
i programming chat app , want save token id in firebase database got token empty. code:
firebaseuser user = firebaseauth.getinstance().getcurrentuser(); string user_id = mauth.getcurrentuser().getuid(); string device_id = firebaseinstanceid.getinstance().gettoken(); toast.maketext(this, device_id, toast.length_short).show(); mdatabasetokenid.child(user_id).child("device_token").setvalue(device_id).addoncompletelistener(new oncompletelistener<void>() { @override public void oncomplete(@nonnull task<void> task) { if (task.issuccessful()){ }else{ toast.maketext(loginactivity.this, ""+task.getexception() , toast.length_short).show(); } } }); if(user.isemailverified()){ intent intent = new intent(getapplicationcontext(),mainactivity.class); intent.addflags(intent.flag_activity_new_task | intent.flag_activity_clear_task); startactivity(intent); finish();
the device_id return empty why? please me, guys.
add service in manifest
<service android:name=".myfirebaseinstanceidservice"> <intent-filter> <action android:name="com.google.firebase.instance_id_event"/> </intent-filter> </service>
you have ontokenrefresh method in service below
@override public void ontokenrefresh() { // updated instanceid token. string refreshedtoken = firebaseinstanceid.getinstance().gettoken(); log.d(tag, "refreshed token: " + refreshedtoken); // todo: implement method send registration app's servers. sendregistrationtoserver(refreshedtoken); }
Comments
Post a Comment