2017-11-20 1 views
0

내 애플리케이션에 인증 페이지를 구현하려고합니다. 내 중포 기지 데이터베이스에 이메일 인증을 활성화하고 코딩 내가 제출 버튼을 클릭하고 디버깅 할 때Firebase 인증 createUserWithEmailAndPassword가 Android에서 작동하지 않습니다.

public class AdminLoginActivity extends AppCompatActivity { 

    private Button loginButton; 
    private EditText inputEmail; 
    private EditText inputPassword; 
    private TextView loginText; 

    //private ProgressDialog progressDialog; 

    //Firebase Authentication Object 

    private FirebaseAuth firebaseAuth; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_admin_login); 

     //progressDialog = new ProgressDialog(AdminLoginActivity.this); 

     firebaseAuth = FirebaseAuth.getInstance(); 

     loginButton = (Button) findViewById(R.id.login_button); 
     inputEmail = (EditText) findViewById(R.id.enter_email); 
     inputPassword = (EditText) findViewById(R.id.enter_password); 

     loginText = (TextView) findViewById(R.id.newaccount_text); 

     loginButton.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       accountLogin(); 

      } 
     }); 

     loginText.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 


      } 
     }); 
    } 

    private void accountLogin() { 
     String email = inputEmail.getText().toString().trim(); 
     String password = inputPassword.getText().toString().trim(); 


     // valid input 
     //progressDialog.setTitle("Loading..."); 
     //progressDialog.setMessage("Logging in..."); 
     //progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
     //progressDialog.show(); 

     // Creates a user with a given email and password in the database 
       (firebaseAuth.createUserWithEmailAndPassword(email, password)) 
      .addOnCompleteListener(AdminLoginActivity.this, new OnCompleteListener<AuthResult>() { 
     @Override 
     public void onComplete(@NonNull Task<AuthResult> task) { 
      if(task.isSuccessful()) { 
       //successfully signed in 
       //start new activity 
       Toast.makeText(AdminLoginActivity.this, "Success", Toast.LENGTH_SHORT).show(); 
       //progressDialog.hide(); 
      } else { 
       Toast.makeText(AdminLoginActivity.this, "Fail", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }); 
    } 
} 

, 그것은이 createUserWithEmailAndPassword 기능에 도달하지 않은 다음과 같이. 그것은 그저 멈춘다. Firebase 데이터베이스를 검사 할 때 아무 것도 추가되지 않습니다.

어떤 오류가 있습니까?

편집 :

11-20 04:58:56.884 12640-12678/ykim164cs242.tournamentor E/FA: Discarding data. Failed to send app launch 
11-20 04:58:56.887 12640-12678/ykim164cs242.tournamentor E/FA: Failed to get app instance id 
11-20 04:58:56.889 12640-12678/ykim164cs242.tournamentor E/FA: Failed to send current screen to service 
11-20 04:58:56.891 12640-12678/ykim164cs242.tournamentor E/FA: Discarding data. Failed to send event to service 

EDIT2

build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.2" 
    defaultConfig { 
     applicationId "-----------" 
     minSdkVersion 15 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     vectorDrawables.useSupportLibrary = true 
    } 
    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:design:26.+' 
    compile 'com.android.support:appcompat-v7:26.+' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    compile 'com.android.support:support-vector-drawable:26.+' 
    compile 'com.google.firebase:firebase-core:11.0.4' 
    compile 'com.google.firebase:firebase-database:11.0.4' 
    compile 'com.google.firebase:firebase-auth:11.0.4' 
    compile 'com.android.support:support-v4:26.+' 
    testCompile 'junit:junit:4.12' 
} 


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

`최고 수준의 Gradle을 '

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.3.3' 
     classpath 'com.google.gms:google-services:3.1.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 
} 

activity_admin_login.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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="ykim164cs242.tournamentor.Activity.Admin.AdminLoginActivity"> 

    <EditText 
     android:hint="Enter your email" 
     android:id="@+id/enter_email" 
     android:layout_margin="15dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <EditText 
     android:id="@+id/enter_password" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="15dp" 
     android:hint="Enter your password" /> 

    <Button 
     android:id="@+id/login_button" 
     android:text="Manage Tournament" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="15dp" /> 

    <TextView 
     android:id="@+id/newaccount_text" 
     android:text="Want to set up a new tournament? Click here" 
     android:textAlignment="center" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

UI

enter image description here

+0

오류 로그를 보내주십시오. 오류 로그가 없으면 오류를 해결할 수 없습니다. –

+0

@AmrishKakadiya 내 앱이 실제로 충돌하는 것이 아니라 내 편집본에 표시된대로 메시지를받는 것 – Dawn17

+0

비밀번호 길이는 firebase auth에서 6보다 커야합니다. 그것을 시도하십시오. –

답변

0

그것은 당신에게 도움이 될 것입니다 중포 기지에서 등록 페이지에이 코드를 시도

private void registerUser(){ 

     username = editTextUsername.getText().toString(); 
     String password = editTextPassword.getText().toString(); 
     String repeatPassword = editTextRepeatPassword.getText().toString(); 

     //checking if email and passwords are empty 
      if (validate(username, password, repeatPassword)) { 
       Toast.makeText(this, "You Passed", Toast.LENGTH_SHORT).show(); 
      }else { 
       Toast.makeText(this, "Invalid email or not match password", Toast.LENGTH_SHORT).show(); 
      } 
     //if the email and password are not empty 
     //displaying a progress dialog 
     progressDialog.setMessage("Registering Please Wait..."); 
     progressDialog.show(); 

     //creating a new user 
     firebaseAuth.createUserWithEmailAndPassword(username, password) 
       .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
        @Override 
        public void onComplete(@NonNull Task<AuthResult> task) { 
         //checking if success 
         if(task.isSuccessful()){ 
          //display some message here 
          Toast.makeText(RegistrationActivity.this,"Successfully registered",Toast.LENGTH_LONG).show(); 
         }else{ 
          //display some message here 
          Toast.makeText(RegistrationActivity.this,"Registration Error",Toast.LENGTH_LONG).show(); 
         } 
         progressDialog.dismiss(); 
        } 
       }); 
    } 
    private boolean validate(String emailStr, String password, String repeatPassword) { 
     Matcher matcher = VALID_EMAIL_ADDRESS_REGEX .matcher(emailStr); 
     return password.length() > 0 && repeatPassword.equals(password) && matcher.find(); 
    } 
+0

@ Dawn17 당신의 gradle 파일과 매니페스트 파일을보고 필요한 항목을 올바르게 추가했는지 또는 firebase 콘솔에 있는지 확인하십시오. 전자 메일을 사용하여 등록 할 수 있습니다. – vinay

+0

@ Dawn17 도움이된다면 도움을 청하십시오. – vinay

+0

코드는 내 모습과 비슷하지만 작동하지 않습니다. – Dawn17

0

그것은 당신이 테스트하기 위해 에뮬레이터를 사용하고 있는지 분명 당신의 이 경우 에뮬레이터를 업데이트하여 Play Services 11을 설치해야합니다.

관련 문제