java - 我的 Firebase 没有为我的应用程序生成 token

标签 java android firebase firebase-realtime-database firebase-authentication

我从我的 firebase 请求一个 token ,但它返回 null,我不知道为什么,但是当我检查日志时,我可以在那里看到我的 token 。 那我能做什么呢?

FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
    @Override
    public void onSuccess(InstanceIdResult instanceIdResult) {

        tokenId = instanceIdResult.getToken();
    }
});

最佳答案

试试这个

FirebaseInstanceId.getInstance().getInstanceId()
                    .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
                        @Override
                        public void onComplete(@NonNull Task<InstanceIdResult> task) {
                            if (!task.isSuccessful()) {
                                Log.w(TAG, "get Instance Id failed", task.getException());
                                return;
                            }

                            // Get new Instance ID token
                            String token = task.getResult().getToken();                             
                        }

});

关于java - 我的 Firebase 没有为我的应用程序生成 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57207257/

相关文章:

java - RxJava插入并返回Id方法(房间)调试

django - 仅适用于推送通知的Firebase

java - 对于 ajax 按钮,如何在 WebElement.click() 之后避免 StaleElementException?

java - Web应用程序: When user submits a second request before the 1st one is "finished" the browser shows the output of the first req.为什么?

android - 我怎样才能返回基本 Activity

java - com.google.firebase.database.DatabaseException : Can't convert object of type java. lang.String 使用 RecyclerView 输入

swift - 使用可编码从 Firebase Cloud Firestore 解码集合数组

java - 对事务和锁定的 jpa 考试感到困惑

java - Android:清除 Activity 堆栈

java - 我可以使用光传感器来测量闪光之间的周期吗?有没有我可以使用的类(class)或者