3 回答
TA贡献1816条经验 获得超6个赞
According to latest docs,you can get new token id from onNewToken Method.<br/>
@Override
public void onNewToken(String s) {
Log.e("NEW_TOKEN", s);
//Implement your business logic to send your device token from here
}
TA贡献1828条经验 获得超3个赞
尝试更改您的 addOnSuccessListener 方法,删除第一个参数,如下所示:
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
//Manage your token
String token = instanceIdResult.getToken();
Log.i("FCM_TOKEN", token);
}
});
TA贡献1810条经验 获得超5个赞
除了 FirebaseMessagingService 之外,还需要添加 FirebaseInstanceIdService
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
public MyFirebaseInstanceIDService() {
}
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
MyNotificationManager.getInstance().registerToken(getApplicationContext(), refreshedToken);
}
}
然后在您的清单中添加:
<service
android:name=".MyFirebaseInstanceIDService"
android:enabled="true"
android:exported="true"/>
添加回答
举报