首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >firebase createUserWithEmailAndPassword在安卓系统中不起作用

firebase createUserWithEmailAndPassword在安卓系统中不起作用
EN

Stack Overflow用户
提问于 2016-06-09 00:15:46
回答 8查看 13.7K关注 0票数 3

我正在尝试使用createUserWithEmailAndPassword方法来创建用户,但是不能这样做。正在调用OnAuthenticate方法,但user对象为null,并且未在firebase控制台中创建任何用户。这是我的代码,也可以在网上找到。

MAinActivity.java

代码语言:javascript
复制
private static FirebaseAuth mAuth;
private static FirebaseAuth.AuthStateListener mAuthListener;
private static String TAG = "RegisterDEbug";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_main);
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            waitForDebugger();
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            // ...
        }
    };
    mAuth.addAuthStateListener(mAuthListener);
    mAuth.createUserWithEmailAndPassword("9199999989@pintech.com", "corrfecthorsebatterystaple")
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    waitForDebugger();
                    Log.d(TAG, "Authentication successful");
                    if (!task.isSuccessful()) {
                        //Toast.makeText(this, "Authentication failed.",  Toast.LENGTH_SHORT).show();
                    }
                }
            });
}

app.properties

代码语言:javascript
复制
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app.gradle

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.pt.reg"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services:9.0.2'
    //compile 'com.google.android.gms:play-services-auth:9.0.2'

    compile 'com.google.firebase:firebase-core:9.0.2'
    compile 'com.google.firebase:firebase-auth:9.0.2'
}

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

注意-我已经尝试了来自firebase的web解决方案来创建一个用户,效果很好。

EN

回答 8

Stack Overflow用户

发布于 2016-07-12 05:01:36

我也有这个问题。我用来测试应用程序的密码太短了。我将其扩展为更长的密码,它起作用了。你必须满足谷歌的密码复杂性标准。

票数 24
EN

Stack Overflow用户

发布于 2020-07-28 20:49:25

我花了两天的时间寻找这个解决方案,结果发现是因为仿真器。尝试使用智能手机来运行您的应用程序。对我来说,它起作用了。

票数 2
EN

Stack Overflow用户

发布于 2017-04-02 22:42:22

我也有同样的问题。

更改:

代码语言:javascript
复制
mAuth.createUserWithEmailAndPassword("9199999989@pintech.com", "corrfecthorsebatterystaple")
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>()

至:

代码语言:javascript
复制
mAuth.createUserWithEmailAndPassword("9199999989@pintech.com", "corrfecthorsebatterystaple")
            .addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37707780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档