簡體   English   中英

后台服務中的Firebase Auth

[英]Firebase Auth in Background Service

我有一個android后台服務,在onCreate()函數上運行

FirebaseAuth mAuth = FirebaseAuth.getInstance();

mAuth.signInWithEmailAndPassword("user@user.com", "password")
    .addOnCompleteListener((Executor)this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                Log.d(Actions.LOG_TAG, "signInWithEmail:success");
                FirebaseUser user = mAuth.getCurrentUser();

            } else {
                Log.w(Actions.LOG_TAG, "signInWithEmail:failure", task.getException());
            }
        }
    });

但它崩潰了。 為什么? 捕獲異常是

網絡提供程序不存在,提供程序不存在:網絡

嘗試調用虛擬方法'com.google.android.gms.tasks.Task com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzde)'在null對象上引用java.lang.NullPointerException:嘗試調用虛擬方法'com.google.android.gms.tasks.Task com.google.android.gms.common.api.GoogleApi.zzb(com.google.android。 gms.common.api.internal.zzde)”上的空對象引用

編輯

將代碼放入MainActivity的onStart()函數中時遇到同樣的問題(遵循本指南https://firebase.google.com/docs/auth/android/password-auth

模擬器未安裝Google Play服務。

Firebase Auth不支持沒有播放服務的設備。

如果要使用Firebase,則需要使用Firebase Admin SDK。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM