Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法从软件包外部访问电话认证卡_Android_Firebase_Firebase Authentication - Fatal编程技术网

Android 无法从软件包外部访问电话认证卡

Android 无法从软件包外部访问电话认证卡,android,firebase,firebase-authentication,Android,Firebase,Firebase Authentication,我正在尝试使用firebase数据库系统在我的android项目中添加电话认证,但我面临“PhoneAuth Cardential”的问题。它显示无法解析phone auth credential,并且无法从软件包外部访问phone auth cardentila。我想使用用户输入的联系号码上的代码发送对用户进行身份验证,以便在身份验证后应允许用户登录 import android.app.ProgressDialog; import android.content.Intent; import

我正在尝试使用firebase数据库系统在我的android项目中添加电话认证,但我面临“PhoneAuth Cardential”的问题。它显示无法解析phone auth credential,并且无法从软件包外部访问phone auth cardentila。我想使用用户输入的联系号码上的代码发送对用户进行身份验证,以便在身份验证后应允许用户登录

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
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.FirebaseException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.rengwuxian.materialedittext.MaterialEditText;

import java.util.concurrent.TimeUnit;

public class Log_in extends AppCompatActivity {

    private MaterialEditText phoneEditText;
    private EditText editText;
    private Button continueButton, sendCode;
    private TextView mainTextView,miniTextVeiw;

    private String phoneNumber;
private boolean phoneAndCode=false;

    private String verificationID;
    private PhoneAuthProvider.ForceResendingToken resendToken;


    private FirebaseAuth firebaseAuth;
    private PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacksInstance;

    private ProgressDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_log_in);
        phoneEditText = (MaterialEditText) findViewById(R.id.phoneEditText);
        continueButton = (Button) findViewById(R.id.continueButton);

        editText = (EditText) findViewById(R.id.editText);
        sendCode = (Button) findViewById(R.id.code);

        mainTextView=findViewById(R.id.textView2);
        miniTextVeiw=findViewById(R.id.textView3);

        firebaseAuth = FirebaseAuth.getInstance();


        sendCode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }


    public void onContinueClick(View v) {


        if(phoneAndCode==false)
        {
            if (phoneEditText.getText().toString() != null && phoneEditText.getText().toString().length() == 11) {

                final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
                phoneNumber = phoneEditText.getText().toString();
                phoneNumber="+92"+phoneNumber.substring(1);

                progressDialog = new ProgressDialog(this);
                progressDialog.setTitle("please wait");
                progressDialog.setMessage("sending code");
                progressDialog.setCancelable(false);
    //            phoneVerifier();
                if (MainActivity.flag == 1) {
                    databaseReference.child("Driver").child(phoneNumber).setValue(null);
                    phoneVerifier();

                } else if (MainActivity.flag == 0) {
              //      Toast.makeText(this,"called for driver and phone number is"+phoneNumber,Toast.LENGTH_SHORT).show();
                    databaseReference.child("Passenger").child(phoneNumber).setValue(null);
                    phoneVerifier();

                }
phoneAndCode=true;

            } else {
                phoneEditText.setError("invalid phone number");
            }
        }
        else if(phoneAndCode==true)
        {
            String verificationCode = null;
            PhoneAuthCredential credential = null;
            if (!(phoneEditText.getText().toString().equals(null))) {
                verificationCode = phoneEditText.getText().toString();
                credential = new PhoneAuthCredential(verificationID, verificationCode);
                signInWithPhoneAuthCredential(credential);
            } else
                phoneEditText.setError("invalid verification code");

        }


    }

    private void phoneVerifier() {

        progressDialog.show();
        callbacksInstance = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

            @Override
            public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
                signInWithPhoneAuthCredential(phoneAuthCredential);
            }

            @Override
            public void onVerificationFailed(FirebaseException e) {
                Snackbar.make(findViewById(R.id.welcomeRoot), "invalid phone number", Snackbar.LENGTH_SHORT).show();
                //if the phone number is wrong;


            }

            public void onCodeSent(String verificationId,
                                   PhoneAuthProvider.ForceResendingToken token) {
                // The SMS verification code has been sent to the provided phone number, we
                // now need to ask the user to enter the code and then construct a credential
                // by combining the code with a verification ID.
                Snackbar.make(findViewById(R.id.welcomeRoot), "code sent", Snackbar.LENGTH_SHORT).show();

                // Save verification ID and resending token so we can use them later
                verificationID = verificationId;
                resendToken = token;


                progressDialog.dismiss();
               // continueButton.setVisibility(View.INVISIBLE);
            //    sendCode.setVisibility(View.VISIBLE);
                continueButton.setText("Send verification code");
                mainTextView.setText("Enter verification code that you have recently received");
                miniTextVeiw.setText("Enter verification code");
                phoneEditText.setHint("enter verification code");
                phoneEditText.setText(null);

                // ...
            }
        };
        PhoneAuthProvider.getInstance().verifyPhoneNumber(
                phoneNumber,        // Phone number to verify
                60,                 // Timeout duration
                TimeUnit.SECONDS,   // Unit of timeout
                this,               // Activity (for callback binding)
                callbacksInstance);        // OnVerificationStateChangedCallbacks

    }

    private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
        firebaseAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {
                            // Sign in success, update UI with the signed-in user's information

                            FirebaseUser user = task.getResult().getUser();
                            if (MainActivity.flag == 0) {
                                startActivity(new Intent(Log_in.this, DriverMapsActivity.class));
                                finish();
                            } else if (MainActivity.flag == 1) {
                                startActivity(new Intent(Log_in.this, CustomerMapsActivity.class));
                                finish();
                            }
                            // ...
                        } else {
                            // Sign in failed, display a message and update the UI
                            Toast.makeText(Log_in.this, "sign in failed try again", Toast.LENGTH_SHORT).show();

                            if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                                // The verification code entered was invalid
                                Toast.makeText(Log_in.this, "You have enterd an INVALID CODE", Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                });

    }

}
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.Bundle;
导入android.support.annotation.NonNull;
导入android.support.design.widget.Snackbar;
导入android.support.v7.app.AppActivity;
导入android.text.TextUtils;
导入android.util.Log;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.google.android.gms.tasks.OnCompleteListener;
导入com.google.android.gms.tasks.Task;
导入com.google.firebase.FirebaseException;
导入com.google.firebase.auth.AuthResult;
导入com.google.firebase.auth.FirebaseAuth;
导入com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
导入com.google.firebase.auth.FirebaseUser;
导入com.google.firebase.auth.PhoneAuthCredential;
导入com.google.firebase.auth.PhoneAuthProvider;
导入com.google.firebase.database.DataSnapshot;
导入com.google.firebase.database.DatabaseError;
导入com.google.firebase.database.DatabaseReference;
导入com.google.firebase.database.FirebaseDatabase;
导入com.google.firebase.database.ValueEventListener;
导入com.rengwxian.materialedittext.materialedittext;
导入java.util.concurrent.TimeUnit;
活动中的公共类日志\u{
私人材料编辑文本电话编辑文本;
私人编辑文本;
私有按钮连续按钮,发送代码;
私有文本视图mainTextView,minitextview;
私有字符串电话号码;
私有布尔phoneAndCode=false;
私有字符串验证ID;
private PhoneAuthProvider.ForceResendingToken resendToken;
私有FirebaseAuth FirebaseAuth;
私有PhoneAuthProvider.OnVerificationStateChangedCallbacks回调实例;
私有进程对话;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u log\u in);
phoneEditText=(MaterialEditText)findViewById(R.id.phoneEditText);
continueButton=(按钮)findViewById(R.id.continueButton);
editText=(editText)findViewById(R.id.editText);
sendCode=(按钮)findViewById(R.id.code);
mainTextView=findViewById(R.id.textView2);
miniTextVeiw=findViewById(R.id.textView3);
firebaseAuth=firebaseAuth.getInstance();
sendCode.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
}
});
}
继续单击上的公共空白(视图v){
如果(phoneAndCode==false)
{
if(phoneEditText.getText().toString()!=null&&phoneEditText.getText().toString().length()=11){
final DatabaseReference DatabaseReference=FirebaseDatabase.getInstance().getReference();
phoneNumber=phoneEditText.getText().toString();
phoneNumber=“+92”+phoneNumber.子字符串(1);
progressDialog=新建progressDialog(此);
progressDialog.setTitle(“请稍候”);
progressDialog.setMessage(“发送代码”);
progressDialog.setCancelable(假);
//电话验证器();
如果(MainActivity.flag==1){
databaseReference.child(“驱动程序”).child(电话号码).setValue(null);
电话验证器();
}else if(MainActivity.flag==0){
//Toast.makeText(这个“调用驱动程序和电话号码为”+phoneNumber,Toast.LENGTH_SHORT).show();
databaseReference.child(“乘客”).child(电话号码).setValue(null);
电话验证器();
}
phoneAndCode=true;
}否则{
phoneEditText.setError(“无效电话号码”);
}
}
else if(phoneAndCode==true)
{
字符串验证代码=null;
PhoneAuthCredential凭证=null;
if(!(phoneEditText.getText().toString().equals(null))){
verificationCode=phoneEditText.getText().toString();
凭证=新的PhoneAuthCredential(verificationID,verificationCode);
使用PhoneAuthCredential(凭证)登录;
}否则
phoneEditText.setError(“无效验证码”);
}
}
私有void phoneVerifier(){
progressDialog.show();
CallbackInstance=new PhoneAuthProvider.OnVerificationStateChangedCallbacks(){
@凌驾
已完成验证的公共无效(PhoneAuthCredential PhoneAuthCredential){
使用phoneAuthCredential(phoneAuthCredential)登录;
}
@凌驾
public void onVerificationFailed(FirebaseException e){
Snackbar.make(findViewById(R.id.welcomeRoot),“无效电话号码”,Snackbar.LENGTH_SHORT.show();
//如果电话号码错了;
}
public void oncodesnt(字符串验证ID,
PhoneAuthProvider.ForceResendingToken(令牌){
//短信验证码已发送至提供的电话号码,我们
//现在需要要求用户输入代码,然后构造凭证
//通过将代码与验证ID相结合。
Snackbar.make(findviewbyd(R.id.welcomeRoot),“发送代码”,Snackbar.LENGTH\u SHORT.sh
credential =PhoneAuthProvider.getCredential(verificationID,verificationCode);
credential = new PhoneAuthCredential(verificationID, verificationCode);