【问题标题】:FIrebase AuthStateListener is not getting called未调用 FIrebase AuthStateListener
【发布时间】:2018-02-02 11:39:28
【问题描述】:

我正在尝试使用 firebase UI 调用 AuthStateListener 以进行 firebase 用户登录,但在执行活动时未调用该方法。我之前为各种应用程序做过相同的过程这是代码:

mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();

            if (firebaseUser != null) {
                Log.d(TAG, "In SignedinFirebaseMethod");

            } else {
                startActivityForResult(
                        AuthUI.getInstance()
                                .createSignInIntentBuilder()
                                .setIsSmartLockEnabled(false)
                                .setProviders(AuthUI.GOOGLE_PROVIDER,
                                        AuthUI.EMAIL_PROVIDER)
                                .build(),
                        RC_SIGN_IN);
            }
        }
    };

这是 Gradle 代码:

android {
compileSdkVersion 25
buildToolsVersion "24.0.1"
defaultConfig {
    applicationId "com.example.hamid_pc.auctionapp"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
 buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'net.danlew:android.joda:2.9.9'
compile 'com.google.firebase:firebase-storage:10.0.1'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.firebaseui:firebase-ui:1.1.1'
testCompile 'junit:junit:4.12'
 }

 apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 发布您的应用模块 build.gradle 文件。
  • @BobSnyder 我已经更新了代码并包含了 gradle 代码
  • 我看不出有什么问题。您的设备是否安装了兼容版本的 Google Play 服务?当您的应用初始化时,您是否在 logcat 中看到 W/GooglePlayServicesUtil: Google Play services out of date 消息?
  • @BobSnyder logcat 中没有显示错误
  • 我收到以下声明:DynamiteModule:未找到 com.google.firebase.auth 的本地模块描述符类。任何建议@BobSnyder

标签: android firebase firebase-authentication firebaseui


【解决方案1】:

在使用 firebase 进行身份验证之前尝试注册监听器。您可能迟到了附加侦听器。

abstract void onAuthStateChanged(FirebaseAuth auth)

当身份验证状态发生变化时,会在 UI 线程中调用此方法:

  • 在监听器注册之后

  • 当用户登录时

  • 当前用户退出时当前用户更改时

【讨论】:

  • 我认为注册监听器不是问题
  • 你能显示活动中的流程吗,什么时候调用 firebaseauth.signin
  • 方法在OnCreate方法中被调用,代码如上
  • 我使用的方法与代码@UmarHussain 中提到的方法相同
  • 那么它可能是一个 Firebase 配置问题,它是否在同一个应用程序中为您更早地工作?
【解决方案2】:

我在启动片段时发现代码中的错误我没有附加监听器

@Override
public void onStart() {
    super.onStart();
    mAuth.addAuthStateListener(mAuthListener);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 2016-11-08
    • 2018-03-16
    • 2018-01-22
    • 1970-01-01
    • 2016-09-23
    • 2021-02-24
    相关资源
    最近更新 更多