2016-06-08 3 views
1

Я пытаюсь использовать метод createUserWithEmailAndPassword для создания пользователей, но не в состоянии сделать это.
Вызывается метод OnAuthenticate, но пользовательский объект имеет значение NULL и пользователь не создается внутри консоли firebase.
Вот мой код, который также доступен в Интернете.firebase createUserWithEmailAndPassword не работает в android

MAinActivity.java

private static FirebaseAuth mAuth; 
private static FirebaseAuth.AuthStateListener mAuthListener; 
private static String TAG = "RegisterDEbug"; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //setContentView(R.layout.activity_main); 
    mAuth = FirebaseAuth.getInstance(); 
    mAuthListener = new FirebaseAuth.AuthStateListener() { 
     @Override 
     public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 
      waitForDebugger(); 
      FirebaseUser user = firebaseAuth.getCurrentUser(); 
      if (user != null) { 
       // User is signed in 
       Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); 
      } else { 
       // User is signed out 
       Log.d(TAG, "onAuthStateChanged:signed_out"); 
      } 
      // ... 
     } 
    }; 
    mAuth.addAuthStateListener(mAuthListener); 
    mAuth.createUserWithEmailAndPassword("[email protected]", "corrfecthorsebatterystaple") 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        waitForDebugger(); 
        Log.d(TAG, "Authentication successful"); 
        if (!task.isSuccessful()) { 
         //Toast.makeText(this, "Authentication failed.", Toast.LENGTH_SHORT).show(); 
        } 
       } 
      }); 
} 

app.properties

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.0' 

     classpath 'com.google.gms:google-services:3.0.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 
} 

app.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    defaultConfig { 
     applicationId "com.pt.reg" 
     minSdkVersion 10 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile 'com.google.android.gms:play-services:9.0.2' 
    //compile 'com.google.android.gms:play-services-auth:9.0.2' 

    compile 'com.google.firebase:firebase-core:9.0.2' 
    compile 'com.google.firebase:firebase-auth:9.0.2' 
} 

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

Нет te - Я пробовал веб-решение от firebase для создания пользователя, который отлично работает.

ответ

12

У меня тоже была эта проблема. Пароль, который я тестировал, был слишком коротким. Я расширил его до более длинного пароля, и он сработал. Вы должны соответствовать стандартам сложности пароля Google.

+0

у спас мое время, поблагодарить у – fayza

1

У меня такая же проблема.

изменение:

mAuth.createUserWithEmailAndPassword("[email protected]", "corrfecthorsebatterystaple") 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() 

к:

mAuth.createUserWithEmailAndPassword("[email protected]", "corrfecthorsebatterystaple") 
      .addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>()