gpt4 book ai didi

Android:createUserWithEmailAndPassword 不起作用(firebase)

转载 作者:行者123 更新时间:2023-11-29 19:16:26 25 4
gpt4 key购买 nike

我正在学习使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com