2017-06-19 74 views
0

我是Android編程新手,作爲實習開發人員工作。使用Firebase無法登錄我的應用程序

我目前正在進行Firebase身份驗證,嘗試執行登錄屏幕。

我在Firebase中添加了一個用戶。當我保留電子郵件或密碼時,程序正確顯示「輸入電子郵件和密碼」(用我的語言)錯誤。但是當我點擊按鈕時,沒有任何反應。毫無意義。

package com.example.jalea.requestingform;

import android.content.Intent; 
import android.preference.EditTextPreference; 
import android.support.annotation.NonNull; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.text.TextUtils; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 

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 AppCompatActivity { 
    EditText edt_email,edt_sifre; 
    Button bt_giris; 
    private FirebaseAuth mAuth; 
    private FirebaseAuth.AuthStateListener authStateListener; 



    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     edt_email = (EditText) findViewById(R.id.et_mail); 
     edt_sifre = (EditText) findViewById(R.id.et_sifre); 
     bt_giris = (Button) findViewById(R.id.btn_giris); 
     mAuth = FirebaseAuth.getInstance(); 
     authStateListener = new FirebaseAuth.AuthStateListener() { 
      @Override 
      public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 
       if(firebaseAuth.getCurrentUser() !=null){ 
        Intent intent = new Intent(MainActivity.this,RequestActivity.class); 
        startActivity(intent); 
       } 
       else{ 
        Log.w("1 : ", "onAuthStateChanged:signed_out"); 
       } 
      } 
     }; 
     bt_giris.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       SignIn(); 
      } 
     }); 
    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 
     mAuth.addAuthStateListener(authStateListener); 
    } 

    @Override 
    protected void onStop() { 
     super.onStop(); 
     if(authStateListener != null) { 
      mAuth.removeAuthStateListener(authStateListener); 
     } 
    } 
    public void SignIn(){ 
     String email = edt_email.getText().toString(); 
     String sifre = edt_sifre.getText().toString(); 

     if(TextUtils.isEmpty(email) || TextUtils.isEmpty(sifre)){ 
      Toast.makeText(MainActivity.this,"Kullanıcı adı veya şifre alanı boş",Toast.LENGTH_LONG).show(); 
     } 
     else{ 
      mAuth.signInWithEmailAndPassword(email,sifre).addOnCompleteListener(new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        if(!task.isSuccessful()){ 
         Toast.makeText(MainActivity.this,"Auth. Problem",Toast.LENGTH_LONG).show(); 
        } 
       } 
      }); 
     } 



    } 
} 

這是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:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.jalea.requestingform.MainActivity" 
    android:padding="16dp"> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="e-mail" 
     android:id="@+id/et_mail" 
     android:layout_marginTop="120dp"/> 
    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="sifre" 
     android:id="@+id/et_sifre" 
     android:layout_marginTop="20dp"/> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Giriş" 
     android:layout_marginTop="20dp" 
     android:id="@+id/btn_giris"/> 

</LinearLayout> 

我在火力地堡添加用戶。當我保持電子郵件或密碼,程序正確顯示「輸入電子郵件和密碼」(以我的語言)錯誤。但是當我點擊按鈕沒有任何反應。從字面上看,什麼都沒有。

5月6日至19日:16:37.143 2453年至2453年/ com.example.jalea.requestingform I /藝術: 晚啓用-Xcheck:JNI 5月6日至19日:16:37.144 2453年至2453年/ com.example.jalea.requestingform W/art:使用默認值X86的意外CPU變體:x86 06-19 05:16:37.729 2453-2453/com.example.jalea.requestingform W/System:ClassLoader引用未知路徑: /data/app/com.example.jalea.requestingform-2/lib/x86 06-19 05:16:38.415 2453-2475/com.example.jalea.requestingform W/DynamiteModule:本地模塊描述符類,用於 com。找不到google.firebase.auth。 06-19 05:16:38.440 2453-2475/com.example.jalea.requestingform W/GooglePlayServicesUtil:Google Play商店缺失。 06-19 05:16:38.484 2453-2453/com.example.jalea.requestingform W/InstanceID/Rpc:無法解析寄存器意圖,回落 06-19 05:16:38.492 2453-2453/com.example .jalea.requestingform W/InstanceID/Rpc:Google Play服務和舊版GSF包都是 丟失 06-19 05:16:38.493 2453-2453/com.example.jalea.requestingform D/FirebaseApp:com.google.firebase .crash.FirebaseCrash未鏈接。 跳過初始化。 06-19 05:16:38.637 2453-2453/com.example.jalea.requestingform I/FA:應用測量正在啓動,版本:10084 06-19 05:16:38.637 2453-2453/com.example。 jalea.requestingform I/FA:啓用調試日誌記錄運行:adb shell setprop log.tag.FA VERBOSE 06-19 05:16:38.637 2453-2453/com.example.jalea.requestingform D/FA:調試級別消息記錄已啓用 06-19 05:16:38.637 2453-2453/com.example.jalea.requestingform D/FA:AppMeasurement單件哈希值:23426705 06-19 05:16:38.733 2453-2453/com.example.jalea .requestingform V/FA:已啓用收集 06-19 05:16:38.740 2453-2453/com.example.jalea.requestingform V/FA:應用程序包,Google應用程序ID:com.example.jalea.requestingform, 1: 274099860490:android:14b27427a401eb21 06-19 05:16:38.740 2453-2453/com.example.jalea.requestingform I/FA:啓用更快的調試模式事件日誌記錄運行: adb shell setprop debug.firebase.analytics.app com.example.jalea .requestingform 06-19 05:16:38.902 2453-2453/com.example.jalea.requestingform V/FA:已註冊的活動生命週期回調 06-19 05:16:38.907 2453-2453/com.example.jalea.requestingform I/FirebaseInitProvider:FirebaseApp初始化成功 06-19 05:16:38.909 2453-2453/com.example.jalea.requestingform I/InstantRun:啓動即時運行服務器:主進程 06-19 05:16:38.946 2453- 2479/com。示例。jalea.requestingform V/FA:使用本地應用程序測量服務 06-19 05:16:39.066 2453-2453/com.example.jalea.requestingform W/art:在Android 4.1之前,方法 android.graphics.PorterDuffColorFilter android。 support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList,android.graphics.PorterDuff $ Mode) 將不正確地覆蓋 中的包私有方法android.graphics.drawable .Drawable 06-19 05:16:39.088 2453-2453/com.example.jalea.requestingform V/FA:onActivityCreated 06-19 05:16:39.273 2453-2479/com.example.jalea.requestingform V/FA :使用本地應用程序測量服務 06-19 05:16:39.273 2453-2479/com.ex ample.jalea.requestingform V/FA:正在進行連接嘗試 06-19 05:16:39.276 2453-2479/com.example.jalea.requestingform V/FA:活動恢復,時間:1695486
[06-19 05:16:39.360 2453:2453 d /]
HostConnection ::得到()新主機連接建立0xe24237c0,TID [5月6日至一十九日:16:39.373 2453:2453 W /]
工藝管道失敗 06-19 05:16:39.383 2453-2453/com.example.jalea.requestingform V/FA:本地AppMeasurementService正在啓動 06-19 05:16:39.391 2453-2453/com.example.jalea.requestingform W/1 :: onAuthStateChanged:signed_out 06-19 05:16:39.532 2453-2482/com.example.jalea.requestingform D/libEGL:仿真器支持主機GPU,qemu.gles設置爲1. 06-19 05:16:39.533 2453-2482/com.example .jalea.requestingform E/libEGL:load_driver(/system/lib/egl/libGLES_emulation.so):dlopen 失敗:找不到庫「/system/lib/egl/libGLES_emulation.so」 06-19 05:16:39.538 2453-2482/com.example.jalea.requestingform D/libEGL:loaded /system/lib/egl/libEGL_emulation.so 06-19 05:16:39.544 2453-2482/com.example.jalea.requestingform D/libEGL:加載/system/lib/egl/libGLESv1_CM_emulation.so 06-19 05:16:39.576 2453-2482/com.example.jalea.requestingform D/libEGL:已加載/system/lib/egl/libGLESv2_emulation.so 06-19 05:16:39.624 2453-2453/com.example.jalea.requestingform V/FA:綁定到IMeasurementService接口 06-19 05:16:39.627 2453-2479/com.example.jalea.requestingform V/FA:連接服務 06-19 05:16:39.628 2453-2479/com.example.jalea.requestingform V/FA :處理排隊服務任務:2 06-19 05:16:39.821 2453-2453/com.example.jalea.requestingform W/art:在Android 4.1之前,方法int android.support.v7.widget.ListViewCompat.lookForSelectablePosition (INT, 布爾)會錯誤地覆蓋了包私有方法 在android.widget.ListView
5月6日至一十九日:16:39.901 2453:2482 d /] HostConnection ::得到()新主機連接建立0xe2423d40 ,tid 06-19 05:16:39.904 2453-2479/com.example.jalea.requestingform I/FA:T他的實例被標記爲上傳者 06-19 05:16:39.947 2453-2479/com.example.jalea.requestingform D/FA:無法獲取廣告ID:java.lang.NullPointerException: 嘗試調用虛擬方法' java.lang.String com.google.android.gms.ads.identifier.AdvertisingIdClient $ Info.getId()' null對象引用: com.google.android.gms.internal.zzatl.zzfK(Unknown Source ) 06-19 05:16:39.951 2453-2482/com.example.jalea.requestingform I/OpenGLRenderer:初始化的EGL,版本1.4 06-19 05:16:39.952 2453-2482/com.example.jalea.requestingform D/OpenGLRenderer:交換行爲1 06-19 05:16:40.080 2453-2482/com.example.jalea。requestingform E/EGL_emulation:TID 2482:eglSurfaceAttrib(1174):錯誤0x3009 (EGL_BAD_MATCH) 5月6日至十九日:16:40.080 2453年至2482年/ com.example.jalea.requestingform W/OpenGLRenderer:無法設置EGL_SWAP_BEHAVIOR上表面 0xf347c320,錯誤= EGL_BAD_MATCH 06-19 05:16:40.891 2453-2453/com.example.jalea.requestingform I /編舞:跳過60幀!其主線程上的應用程序可能也做了太多的工作。 06-19 05:16:44.904 2453-2479/com.example.jalea.requestingform V/FA:不活動,與服務斷開連接 06-19 05:16:44.909 2453-2453/com.example.jalea.requestingform V/FA:onUnbind呼籲意圖。操作: com.google.android.gms.measurement.START 06-19 05:16:44.920 2453-2453/com.example.jalea.requestingform V/FA:本地AppMeasurementService正在關閉 06-19 05:16 :49.286 2453-2479/com.example.jalea.requestingform V/FA:會話已啓動,時間:1705500 06-19 05:16:49.295 2453-2479/com.example.jalea.requestingform I/FA:代碼管理器是未找到,因此不會被使用 06-19 05:16:49.307 2453-2479/com.example.jalea.requestingform D/FA:記錄事件(FE):_s,Bundle [{_ o = auto,_sc = MainActivity , _si = -6096220152962165033}] 06-19 05:16:49.395 2453-2479/com.example.jalea.requestingform V/FA:使用本地應用測量服務 06-19 05:16:49.414 2453-2453/com.example.jalea.requestingform V/FA:本地AppMeasurementServic e正在啓動 06-19 05:16:49.417 2453-2453/com.example.jalea.requestingform V/FA:綁定到IMeasurementService接口 06-19 05:16:49.420 2453-2479/com.example.jalea .requestingform V/FA:連接到服務 06-19 05:16:49.420 2453-2479/com.example.jalea.requestingform V/FA:處理排隊服務任務:1 06-19 05:16:49.512 2453 -2479/com.example.jalea.requestingform V/FA:記錄事件: origin = auto,name = _s,params = Bundle [mParcelledData.dataSize = 108] 06-19 05:16:49.584 2453-2479/com .example.jalea.requestingform V/FA:保存事件,名稱,數據大小:_s,58 06-19 05:16:49.588 2453-2479/com.example.jalea.requestingform V/FA:事件記錄:事件{ appId ='com.example.jalea.requestingform', name ='_ s',params = Bundle [{_ o = auto,_sc = MainActivity, _si = -6096220152962165033}]} 06-19 05:16:49.660 2453-2479/com.example.jalea.requestingform V/FA:上傳計劃時間約爲ms:2103350 06-19 05 :16:49.671 2453-2479/com.example.jalea.requestingform V/FA:後臺事件處理時間,ms:160 06-19 05:16:53.330 2453-2453/com.example.jalea.requestingform W/IInputConnectionWrapper :finishComposingText處於非活動狀態 InputConnection 06-19 05:16:54.519 2453-2479/com.example.jalea.requestingform V/FA:不活動,斷開與服務的連接 06-19 05:16:54.524 2453-2453/com .example.jalea.requestingform V/FA:onUnbind調用intent。操作: com.google.android.gms.measurement.START 06-19 05:16:54.534 2453-2453/com.example.jalea.requestingform V/FA:本地AppMeasurementService正在關閉 06-19 05:16 :58.759 2453-2475/com.example.jalea.requestingform W/DynamiteModule:找不到 com.google.firebase.auth的本地模塊描述符類。 06-19 05:16:58.764 2453-2475/com.example.jalea.requestingform W/GooglePlayServicesUtil:Google Play商店缺失。 06-19 05:17:00.113 2453-2475/com.example.jalea.requestingform W/DynamiteModule:找不到 com.google.firebase.auth的本地模塊描述符類。 06-19 05:17:00.116 2453-2475/com.example.jalea.requestingform W/GooglePlayServicesUtil:Google Play商店缺失。

+0

是你的密碼超過6個字符? –

+0

是的,它是8個字符。 –

回答

1

請確保您已經添加了以下您的gradle這個(依賴)

編譯 'com.google.android.gms:發揮服務的廣告:9.4.0'

編譯「com.google.firebase:火力核心:9.4.0」

確保您已啓用了火力控制檯 (認證)的密碼登錄

使用下面的代碼進行登錄使用電子郵件和PWD

FirebaseAuth mAuth = FirebaseAuth.getInstance(); // same auth as you used for regestration process 
mAuth.signInWithEmailAndPassword("[email protected]","pwd") 
       .addOnCompleteListener(new OnCompleteListener<AuthResult>() { 
        @Override 
        public void onComplete(@NonNull Task<AuthResult> task) { 
         if(task.isSuccessful()){ 

         } 

        }}) 
       .addOnFailureListener(new OnFailureListener() { 
        @Override 
        public void onFailure(@NonNull Exception e) { 

         Toast.makeText(LoginActivity.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); 
        } 
       }); 

當你獲得成功登錄比AUTH變化聽者將被調用

驗證更改聽者

private FirebaseAuth.AuthStateListener mAuthListener; 
mAuthListener = new FirebaseAuth.AuthStateListener() { 
      @Override 
      public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 
       FirebaseUser user = firebaseAuth.getCurrentUser(); 
       if(user !=null){ 

       } 
      } 
     }; 


mAuth.addAuthStateListener(mAuthListener); 
+0

我做了簡單的Google登錄。我需要使用Firebase做些什麼才能讓用戶使用Firebase控制檯?因爲只有登錄工程 – soommy12

+0

在我們開始使用Firebase服務之前,有幾件事情需要我們在服務器端和應用端進行......以便正確設置Firebase ......首先,您需要有一個Google帳戶...如果您已經有一個Gmail帳戶,您可以訪問console.firebase.google.com ...我們只需使用我們的Gmail帳戶登錄...登錄後,您將被帶到主要控制檯...列出你創建的所有項目,...如果你有任何... ... –

+0

是的,我已經知道了我自己。說實話,這並不難。 Firebase是非常簡單的後端服務器! – soommy12

相關問題