我在GCM中遇到問題,所以我遷移到FCM但我仍然收到與令牌相關的問題。FCM令牌不是在一些Android設備中生成的
我推出了我的更新的應用程序,我檢查了300個新用戶, 其中200個獲取令牌,100個沒有獲取任何令牌,這是一個非常關鍵的問題。
空令牌的任何解決方案?
我在GCM中遇到問題,所以我遷移到FCM但我仍然收到與令牌相關的問題。FCM令牌不是在一些Android設備中生成的
我推出了我的更新的應用程序,我檢查了300個新用戶, 其中200個獲取令牌,100個沒有獲取任何令牌,這是一個非常關鍵的問題。
空令牌的任何解決方案?
您在每次全新安裝時從MyInstanceIDListenerService類onTokenRefresh()方法獲取FCM令牌。
或者你也可以得到FCM令牌這行代碼:
FirebaseInstanceId.getInstance().getToken();
謝謝@阿倫Dey –
謝謝工作。 – Debasish
class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onTokenRefresh() {
//Getting registration token
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
//Displaying token in logcat
Log.e(TAG, "Refreshed token: " + refreshedToken);
}
private void sendRegistrationToServer(String token) {
//You can implement this method to store the token on your server
//Not required for current project
}
}
**Sometimes tokens are not generated then write this code**
public class ContCreateTokenService extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent serviceIntent = new Intent(this, MyFirebaseMessagingService.class);
startService(serviceIntent);
return START_REDELIVER_INTENT;
}
}
public class FetchNewRefreshToken extends IntentService {
/**
* Creates an IntentService. Invoked by your subclass's constructor.
*
* @param name Used to name the worker thread, important only for debugging.
*/
public static final String TAG = FetchNewRefreshToken.class.getSimpleName();
public FetchNewRefreshToken() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
try {
// Resets Instance ID and revokes all tokens.
FirebaseInstanceId.getInstance().deleteInstanceId();
// Now manually call onTokenRefresh()
Log.e(TAG, "Getting new token");
FirebaseInstanceId.getInstance().getToken();
} catch (Exception e) {
e.printStackTrace();
}
}
}
而且它添加Menifest文件
<service android:name=".ContCreateTokenService" />
<service android:name=".FetchNewRefreshToken " />
在飛濺活動: -
startService(new Intent(this, FetchNewRefreshToken.class));
startService(new Intent(this, ContCreateTokenService.class));
紮根電話不生成令牌我怎樣才能生成紮根電話令牌 –
檢查我的更新代碼...它可以在任何設備 –
不工作在我的手機 –
有您是否實現了FCM令牌更新偵聽器? –
您可以發佈清單和令牌更新服務類代碼嗎? –
其工作正常,但它在一些設備中得到的問題。 –