2017-11-20 17 views
0

で働いていません。 私はfirebaseデータベースに電子メール認証を有効にして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データベースをチェックすると、何も追加されません。

私は何を作っているのですか?

EDIT:

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私のアプリは実際にはクラッシュしていませんが、EDIT – 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

は、あなたはそれが参考に私のような – vinay

+0

を使用して登録有効にあなたが必要なものを追加して、正しくかfirebaseコンソールで確認してくださいあなたのGradleファイルとマニフェストファイルを参照してください – vinay

+0

コードはかなりルックスをupvoteしてください見つけて、それが仕事をdoesntの場合は、Dawn17 @メール – Dawn17

0

を助けるfirebaseで登録ページにこのコードを試してみてくださいこの場合、エミュレータをアップデートしてPlay Services 11をインストールする必要があります。

関連する問題