简体   繁体   中英

Firebase database authentication sign-up

I'm connecting my app to database with authentication using email and password in signing in users, the whole code is alright and has no errors until to running the app where the sign registration fails, help Heres my code for App gradle

"apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.gmail.yobimwaura.talktome"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
configurations {
    // Initializes a placeholder for the freeDebugRuntimeOnly dependency
    // configuration.
    freeDebugRuntimeOnly {}
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-core:16.0.5'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
}
apply plugin: 'com.google.gms.google-services'"

Sign in activity java file

"package com.gmail.yobimwaura.talktome;

import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
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;
import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.auth.FirebaseUser;


public class signup extends AppCompatActivity {
FirebaseAuth firebaseAut;

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


        firebaseAut = FirebaseAuth.getInstance();

        TextView textView2 = (TextView) findViewById(R.id.textView2);
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(signup.this, login.class);
                startActivity(intent);
            }
        });

        Button button5 = (Button) findViewById(R.id.button5);
        button5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        Button button4 = (Button) findViewById(R.id.button4);
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (validate()) {
                    //upload data to database
                    EditText editText3 = (EditText) findViewById(R.id.editText3);
                    EditText editText4 = (EditText) findViewById(R.id.editText4);

                    String Email = editText3.getText().toString().trim();
                    String Password = editText4.getText().toString().trim();

                    firebaseAut.createUserWithEmailAndPassword(Email,Password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                Toast.makeText(signup.this, "Registration Successful", Toast.LENGTH_SHORT).show();
                                startActivity(new Intent(signup.this, login.class));
                            } else {
                                Toast.makeText(signup.this, "Registration Fail", Toast.LENGTH_SHORT).show();
                            }

                        }
                    });

                }
            }
        });
    }
    private Boolean validate () {
        Boolean result =false;
        EditText editText3= (EditText) findViewById(R.id.editText3);
        EditText editText4= (EditText) findViewById(R.id.editText4);
        String Email=editText3.getText().toString();
        String Password=editText4.getText().toString();

        if(Email.isEmpty() || Password.isEmpty() ) {
            Toast.makeText(this, "Fill details to continue", Toast.LENGTH_SHORT).show();
        }else{
            result=true;

        }
        return result;

    }
}"

If you need any other code ask for it, once I press the sign-in button 4 it displays 'registration failed' yet the empty textbox tag is working once clicked, my app has successfully connected to the database firebase

@AlexMamo Heres the log cat, still cant find the error @AliAhmed @HarKal,

.INTERACT_ACROSS_USERS_FULL of 10042 is denied.
2018-11-24 16:52:54.922 1060-1071/? W/PackageManager: checkUidPermission(): android.permission.REAL_GET_TASKS of 10042 is denied.
2018-11-24 16:52:55.174 1259-1531/? D/NetworkController.MobileSignalController(1): onDataActivity: direction=2
2018-11-24 16:52:55.180 1259-1531/? D/NetworkController.MobileSignalController(1): Change in state from: connected=true,enabled=true,level=4,inetCondition=0,iconGroup=IconGroup(4G),activityIn=true,activityOut=true,rssi=0,lastModified=11-24 04:52:54,dataSim=true,networkName=Telkom,networkNameData=Telkom,dataConnected=true,isDefault=true,isEmergency=false,airplaneMode=false,carrierNetworkChangeMode=false,userSetup=true,activity=3,dataType=13,signalStrengthLvl=4,signalStrengSlaveLvl=4,signalType=13,signalTypeEx=13,signalSingleMode=true,isRoaming=false,isPoweroff=false,volteState=4,subId=1,slotId=0,
        to: connected=true,enabled=true,level=4,inetCondition=0,iconGroup=IconGroup(4G),activityIn=false,activityOut=true,rssi=0,lastModified=11-24 04:52:54,dataSim=true,networkName=Telkom,networkNameData=Telkom,dataConnected=true,isDefault=true,isEmergency=false,airplaneMode=false,carrierNetworkChangeMode=false,userSetup=true,activity=2,dataType=13,signalStrengthLvl=4,signalStrengSlaveLvl=4,signalType=13,signalTypeEx=13,signalSingleMode=true,isRoaming=false,isPoweroff=false,volteState=4,subId=1,slotId=0,
2018-11-24 16:52:55.182 1259-1259/? D/guohao: getSignalStrengthBigIcon
2018-11-24 16:52:55.182 1259-1259/? D/guohao: strength = 4
2018-11-24 16:52:55.182 1259-1259/? D/guohao: slotId = 0
2018-11-24 16:52:55.182 1259-1259/? D/guohao: QKCommRunMode.getDefault().isLEOS() = true
2018-11-24 16:52:55.182 1259-1259/? D/guohao: QKCommRunMode.getDefault().getCustomPrefrence(QKCommRunMode.CUSTOM_SHOW_SIGNAL_5_GRADE) = null
2018-11-24 16:52:55.182 1259-1259/? D/SignalClusterView: guohao not CUSTOM_SHOW_SIGNAL_5_GRADE
2018-11-24 16:52:55.182 1259-1259/? D/SignalClusterView: guohao QKCommRunMode.getDefault().isCUCCVision() = false
2018-11-24 16:52:55.187 1259-1259/? V/QKCommRunMode: isForeignVersion mVersion = 1
2018-11-24 16:52:55.188 1259-1259/? D/SignalClusterView: setVolteState cancel notify HD--------------
2018-11-24 16:52:55.188 1259-1259/? D/QikuMultiSignalView: SetDataNetworkVisible mSlotId = 0 mSubId = 1 visibile = true
2018-11-24 16:52:55.188 1259-1259/? D/QikuMultiSignalView: SetDataNetworkVisible mSlotId = 1 mSubId = 2 visibile = false
2018-11-24 16:52:55.188 1259-1259/? D/guohao: getSignalStrengthBigIcon
2018-11-24 16:52:55.188 1259-1259/? D/guohao: strength = 4
2018-11-24 16:52:55.188 1259-1259/? D/guohao: slotId = 0
2018-11-24 16:52:55.188 1259-1259/? D/guohao: QKCommRunMode.getDefault().isLEOS() = true
2018-11-24 16:52:55.188 1259-1259/? D/guohao: QKCommRunMode.getDefault().getCustomPrefrence(QKCommRunMode.CUSTOM_SHOW_SIGNAL_5_GRADE) = null

Here is an example, make sure to add the context:

mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(**this**, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
\\OnSuccessful
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM