[英]create user with email and password in firebase
I am going to create a chat application.So for example i have two EditText ,which take email and password.I want to create user authentication with email and password on Google Firebase .我将创建一个聊天应用程序。例如,我有两个 EditText,它们接收电子邮件和密码。我想在 Google Firebase 上使用电子邮件和密码创建用户身份验证。 My code does not work.I can not find my error.Please give me a solution.我的代码不起作用。我找不到我的错误。请给我一个解决方案。
activity_main活动主
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.atik_faysal.test.MainActivity">
<EditText
android:id="@+id/e_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="52dp"
android:layout_marginStart="52dp"
android:layout_marginTop="36dp"
android:ems="10"
android:inputType="textPersonName" />
<EditText
android:id="@+id/e_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:ems="10"
android:inputType="textPassword"
android:layout_below="@+id/e_email"
android:layout_alignLeft="@+id/e_email"
android:layout_alignStart="@+id/e_email" />
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="signIn"
android:layout_marginTop="16dp"
android:text="Log in"
android:layout_below="@+id/e_password"
android:layout_alignLeft="@+id/e_password"
android:layout_alignStart="@+id/e_password" />
<Button
android:id="@+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="registerUser"
android:text="registerUser"
android:layout_alignBaseline="@+id/login"
android:layout_alignBottom="@+id/login"
android:layout_toRightOf="@+id/login"
android:layout_toEndOf="@+id/login"
android:layout_marginLeft="27dp"
android:layout_marginStart="27dp" />
</RelativeLayout>
MainActivity.java主活动.java
package com.example.atik_faysal.test;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.firebase.client.Firebase;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class MainActivity extends Activity {
private EditText editTextEmail;
private EditText editTextPassword;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseAuth = FirebaseAuth.getInstance();
editTextEmail = (EditText) findViewById(R.id.e_email);
editTextPassword = (EditText) findViewById(R.id.e_password);
}
public void registerUser(View view){
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
if(TextUtils.isEmpty(email)){
Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this,"Please enter password",Toast.LENGTH_LONG).show();
return;
}
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(MainActivity.this,"Registration Complete",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(MainActivity.this,"Registration Error",Toast.LENGTH_LONG).show();
}
}
});
}
}
App level dependecy应用级依赖
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
defaultConfig {
applicationId "com.example.atik_faysal.test"
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(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/mail.jar')
compile 'com.google.firebase:firebase-database:11.4.0'
compile 'com.google.firebase:firebase-auth:11.4.0'
compile 'com.google.firebase:firebase-crash:11.4.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.cuboid:cuboidcirclebutton:1.0.3'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
testCompile 'junit:junit:4.12'
debugCompile 'com.android.support.constraint:constraint-layout:1.0.2'
}
apply plugin: 'com.google.gms.google-services'
How about you make your app accepts specific links, eg您如何让您的应用接受特定链接,例如
<data android:pathPrefix="www.example.com" android:scheme="http"/>
Then you send a link, eg http://www.example.com/abcd
,to the email and the user should open it with the app, at the end the app will check if the link "opened link" is the same as the "sent link".然后你发送一个链接,例如http://www.example.com/abcd
到电子邮件,用户应该用应用程序打开它,最后应用程序将检查链接“打开的链接”是否与“发送链接”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.