我尝试更新我的应用程序,但是当应用程序应该生成令牌时,我向我显示错误。 我的应用显示未生成令牌。
我的Firebase代码如下:
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
storeToken(refreshedToken);
}
private void storeToken(String token) {
//saving the token on shared preferences
SharedPreference.getInstance(getApplicationContext()).saveDeviceToken(token);
}
}
我最近迁移到了AndroidX,我不知道我的代码有什么好处
我尝试这个,但不起作用,我没有生成的令牌
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.messaging.FirebaseMessagingService;
public class MyFirebaseInstanceIDService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onNewToken(String token) {
super.onNewToken(token);
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
storeToken(refreshedToken);
}
private void storeToken(String token) {
//saving the token on shared preferences
SharedPreference.getInstance(getApplicationContext()).saveDeviceToken(token);
}
}
请看这个
public class MyFirebaseInstanceIDService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onNewToken(String token) { // this is the "token"
super.onNewToken(token);
storeToken(token);
}
private void storeToken(String token) {
//saving the token on shared preferences
SharedPreference.getInstance(getApplicationContext()).saveDeviceToken(token);
}
}
请尝试此代码。
希望这会有所帮助!