亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我不能給 Token Firebase

我不能給 Token Firebase

慕森王 2021-11-11 18:06:44
MyFirebaseMessagingService.java:public class MyFirebaseMessagingService extends FirebaseMessagingService {    @Override    public void onNewToken(String s) {        Log.e("NEW_TOKEN", s);    }    @Override    public void onMessageReceived(RemoteMessage remoteMessage) {        Map<String, String> params = remoteMessage.getData();        JSONObject object = new JSONObject(params);        Log.e("JSON_OBJECT", object.toString());        String NOTIFICATION_CHANNEL_ID = "Nilesh_channel";        long pattern[] = {0, 1000, 500, 1000};        NotificationManager mNotificationManager =                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Your Notifications",                    NotificationManager.IMPORTANCE_HIGH);            notificationChannel.setDescription("");            notificationChannel.enableLights(true);            notificationChannel.setLightColor(Color.RED);            notificationChannel.setVibrationPattern(pattern);            notificationChannel.enableVibration(true);            mNotificationManager.createNotificationChannel(notificationChannel);        }        // to diaplay notification in DND Mode        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {            NotificationChannel channel = mNotificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);            channel.canBypassDnd();        }        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);        mNotificationManager.notify(1000, notificationBuilder.build());    }}跳過MainActivity 中的此代碼。我不知道該怎么辦。Firebase OAuth 完美運行。但是沒有令牌,我無法檢查 Firebase 通知?,F在是調試模式。也許我必須更改它才能發布?請幫我。
查看完整描述

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

        }


查看完整回答
反對 回復 2021-11-11
?
倚天杖

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);


        }

    });


查看完整回答
反對 回復 2021-11-11
?
森欄

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"/>


查看完整回答
反對 回復 2021-11-11
  • 3 回答
  • 0 關注
  • 235 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號