Android:createUserWithEmailAndPassword 不起作用(firebase)

标签 android firebase firebase-authentication

我正在学习使用 Firebase,并开始创建我可以在 Firebase 控制台中看到的用户和密码。但是,方法 createUserWithEmailAndPassword 不起作用,我不知道为什么,可能是 Gradle 的问题。 这是主要代码:

public class MainActivity extends AppCompatActivity
{
DialogProgress dialogProgress;
EditText editEmail;
EditText editPassword;
String email;
String password;
FirebaseAuth firebaseAuth;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    editEmail = (EditText) findViewById(R.id.editEmail);
    editPassword = (EditText) findViewById(R.id.editPassword);
    firebaseAuth = FirebaseAuth.getInstance();

    findViewById(R.id.registrazione).setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            email = editEmail.getText().toString();
            password = editPassword.getText().toString();
            if(TextUtils.isEmpty(email))
            {
                Toast.makeText(getApplicationContext(),"Email vuota",Toast.LENGTH_SHORT).show();
            }

            if(TextUtils.isEmpty(password))
            {
                Toast.makeText(getApplicationContext(),"Password vuota",Toast.LENGTH_SHORT).show();
            }

            if(!(TextUtils.isEmpty(email)||TextUtils.isEmpty(password)))
            {
                dialogProgress = new DialogProgress();
                dialogProgress.show(getSupportFragmentManager().beginTransaction(),"Dialog");
                firebaseAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>()
                {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task)
                    {
                        if(task.isSuccessful())
                        {
                            Toast.makeText(getApplicationContext(),"Registrazione avvenuta",Toast.LENGTH_SHORT).show();
                            getSupportFragmentManager().beginTransaction().remove(dialogProgress);
                        }
                        else
                        {
                            Toast.makeText(getApplicationContext(), "Registrazione fallita", Toast.LENGTH_SHORT).show();
                            getSupportFragmentManager().beginTransaction().remove(dialogProgress);
                        }
                    }
                });

            }
        }
    });
}
}

这是我的 gradle 项目:

buildscript 
{
  repositories 
  {
    jcenter()
  }
  dependencies 
  {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'com.google.gms:google-services:3.0.0'
  }
}

allprojects 
{
  repositories 
  {
    jcenter()
  }
}

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

这是我的 gradle 应用程序:

apply plugin: 'com.android.application'

android 
{
compileSdkVersion 25
buildToolsVersion "25.0.2"
  defaultConfig 
  {
    applicationId "com.example.utente.myfirebase"
    minSdkVersion 15
    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.1.0'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-auth:10.0.1'
}
apply plugin: 'com.google.gms.google-services'

最佳答案

尝试记录结果,以便您可以使用 Log.d("FirebaseAuth", "onComplete"+ task.getException().getMessage()); 了解问题所在可能是因为您没有激活身份验证登录方法中的电子邮件/密码选项,或者您的密码少于 6 个字符。

enter image description here

关于Android:createUserWithEmailAndPassword 不起作用(firebase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43395123/

相关文章:

android - Firebase user.getDisplayName() 返回 null

swift - 无法从 Firebase 加载我当前用户的帖子 - Swift

android - 在 alertdialog-Android 中更改 ImageView 的可见性

android - 为电话号码格式化 EditText View

android - flutter中onbackpressed的等效方法是什么

firebase - 为切换用户保存信息 Firebase 登录用户无需重新验证?

ios - 第二次登录后无法重新验证 Google 登录。 ( swift 3)(火力基地)

android - 与 android RIL 守护进程通信或拦截来自 RIL android 守护进程的消息

firebase - 字段 SCREEN_VIEW 不是有效维度

android - Firebase 电话身份验证中的验证是什么意思