Android 提供的电话格式不正确
我正在尝试从我的应用程序使用电话身份验证。我已经设置了一个电话编辑文本,让一个人填写自己的电话号码,然后将其发送到要验证的VerificationPhone活动,以使一个人能够使用该应用程序。这是工作之前,但现在我似乎无法理解为什么在填写了电话号码后,我仍然得到的电话格式是正确的,但我已经把国家代码和号码。请帮忙,我似乎不明白 这是splash.classAndroid 提供的电话格式不正确,android,firebase-authentication,Android,Firebase Authentication,我正在尝试从我的应用程序使用电话身份验证。我已经设置了一个电话编辑文本,让一个人填写自己的电话号码,然后将其发送到要验证的VerificationPhone活动,以使一个人能够使用该应用程序。这是工作之前,但现在我似乎无法理解为什么在填写了电话号码后,我仍然得到的电话格式是正确的,但我已经把国家代码和号码。请帮忙,我似乎不明白 这是splash.class public class Splash extends AppCompatActivity { Button btnSi
public class Splash extends AppCompatActivity {
Button btnSignUp, btnFacebook;
TextView tvSignIn;
TextView textSlogan ,alreadyAnAcc;
RelativeLayout rootLayout;
String number;
String phoneVerificationId;
PhoneAuthProvider.OnVerificationStateChangedCallbacks verificationCallbacks;
PhoneAuthProvider.ForceResendingToken resendingToken;
FirebaseAuth mAuth;
private static final String TAG = "Splash";
FirebaseDatabase mCustomerDatabase;
DatabaseReference db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
tvSignIn=(TextView)findViewById(R.id.tvSignIn);
alreadyAnAcc = (TextView)findViewById(R.id.alreadyAnAcc);
btnSignUp=(Button)findViewById(R.id.btnSignUp);
btnFacebook = (Button)findViewById(R.id.btnFacebook);
textSlogan = (TextView)findViewById(R.id.textSlogan);
tvSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showLoginDialog();
}
});
btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showRegisterDialog();
}
});
}
private void showLoginDialog() {
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("LOG IN");
dialog.setMessage("Enter phone and password to sign in");
LayoutInflater inflater = LayoutInflater.from(this);
View login_layout = inflater.inflate(R.layout.content_signin,null);
final EditText edtPhone = login_layout.findViewById(R.id.edtPhone);
final EditText edtPassword = login_layout.findViewById(R.id.edtPassword);
final TextView phoneNumber = login_layout.findViewById(R.id.phoneNum);
final CountryCodePicker countryCodePicker = login_layout.findViewById(R.id.ccp);
countryCodePicker.registerCarrierNumberEditText(edtPhone);
dialog.setView(login_layout);
//set button
dialog.setPositiveButton("SIGN IN", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
//Check validation
//set signin btn enable false while processing
String mobile = edtPhone.getText().toString().trim();
btnSignUp.setEnabled(false);
if(mobile.isEmpty() || mobile.length() < 9){
edtPhone.setError("Enter a valid mobile");
edtPhone.requestFocus();
return;
}
number = countryCodePicker.getFullNumberWithPlus();
Intent intent = new Intent(Splash.this, VerficationPhone.class);
intent.putExtra("mobile", mobile);
startActivity(intent);
final AlertDialog waitingDialog = new SpotsDialog(Splash.this);
waitingDialog.show();
waitingDialog.dismiss();
startActivity(new Intent(Splash.this,VerficationPhone.class));
}
});
dialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
dialogInterface.dismiss();
}
});
dialog.show();
}
private void showRegisterDialog() {
final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("SIGN UP");
dialog.setMessage("Please use email to sign up");
LayoutInflater inflater = LayoutInflater.from(this);
View register_layout = inflater.inflate(R.layout.activity_registration,null);
final EditText edtEmail = register_layout.findViewById(R.id.edtEmail);
final EditText edtPassword = register_layout.findViewById(R.id.edtPassword);
final EditText edtPhone = register_layout.findViewById(R.id.edtPhone);
final EditText edtFirstName = register_layout.findViewById(R.id.edtFirstName);
final EditText edtLastName = register_layout.findViewById(R.id.edtLastName);
final CountryCodePicker countryCodePicker = register_layout.findViewById(R.id.ccp);
countryCodePicker.registerCarrierNumberEditText(edtPhone);
dialog.setView(register_layout);
//set button
dialog.setPositiveButton("SIGN UP", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
//Check validation
String firstName = edtFirstName.getText().toString().trim();
if (TextUtils.isEmpty(edtFirstName.getText().toString()))
{
Snackbar.make(rootLayout,"Please enter first name", Snackbar.LENGTH_SHORT)
.show();
return;
}
Intent intent1 = new Intent(Splash.this,VerficationPhone.class);
intent1.putExtra("firstName",firstName);
startActivity(intent1);
String lastName = edtLastName.getText().toString();
if (TextUtils.isEmpty(edtLastName.getText().toString()))
{
Snackbar.make(rootLayout,"Please enter last name", Snackbar.LENGTH_SHORT)
.show();
return;
}
Intent intent2 = new Intent(Splash.this, VerficationPhone.class);
intent2.putExtra("lastName",lastName);
startActivity(intent2);
String email = edtEmail.getText().toString();
if (TextUtils.isEmpty(edtEmail.getText().toString()))
{
Snackbar.make(rootLayout,"Please enter email address", Snackbar.LENGTH_SHORT)
.show();
return;
}
Intent intent4 = new Intent(Splash.this, VerficationPhone.class);
intent4.putExtra("email", email);
startActivity(intent4);
String password = edtPassword.getText().toString();
if (TextUtils.isEmpty(edtPassword.getText().toString()))
{
Snackbar.make(rootLayout,"Please enter password", Snackbar.LENGTH_SHORT)
.show();
return;
}
Intent intent3 = new Intent(Splash.this, VerficationPhone.class);
intent3.putExtra("password", password);
startActivity(intent3);
if (TextUtils.isEmpty(edtPhone.getText().toString()))
{
Snackbar.make(rootLayout,"Please enter phone number", Snackbar.LENGTH_SHORT)
.show();
return;
}
String mobile = edtPhone.getText().toString().trim();
if(mobile.isEmpty() || mobile.length() < 9){
edtPhone.setError("Enter a valid mobile");
edtPhone.requestFocus();
return;
}
number = countryCodePicker.getFullNumberWithPlus();
Intent intent = new Intent(Splash.this, VerficationPhone.class);
intent.putExtra("mobile", mobile);
startActivity(intent);
final AlertDialog waitingDialog = new SpotsDialog(Splash.this);
waitingDialog.show();
waitingDialog.dismiss();
startActivity(new Intent(Splash.this,VerficationPhone.class));
}
});
dialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
dialogInterface.dismiss();
}
});
dialog.show();
}
}
你能在你的日志中显示android Studio的错误吗?你从哪里得到错误消息?直接从手机中获取。不是日志。我的手机号码字符串似乎没有传递给其他活动。。请告诉我“提供的电话号码格式不正确。请以可解析为E.164格式的格式输入电话号码。E.164电话号码以[+][国家代码][用户号码,包括区号]格式写入。”
public class VerficationPhone extends AppCompatActivity {
String mVerificationId;
//The edittext to input the code
EditText editTextCode;
//firebase auth object
FirebaseAuth mAuth;
private static final String TAG = "PhoneAuth";
String number;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks verificationCallbacks;
private PhoneAuthProvider.ForceResendingToken resendingToken;
FirebaseDatabase db;
DatabaseReference mCustomerDatabase;
RelativeLayout rootLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verfication);
mAuth = FirebaseAuth.getInstance();
editTextCode = (EditText) findViewById(R.id.editTextCode);
mAuth = FirebaseAuth.getInstance();
db = FirebaseDatabase.getInstance();
mCustomerDatabase = db.getReference(Common.customer_tbl);
rootLayout = (RelativeLayout)findViewById(R.id.rootLayout);
//getting mobile number from the previous activity
//and sending the verification code to the number
Intent intent = getIntent();
String mobile = intent.getStringExtra("mobile");
sendVerificationCode(mobile);
Intent intent1 = getIntent();
String password = intent1.getStringExtra("password");
Intent intent2 = getIntent();
String firstName = intent2.getStringExtra("firstName");
Intent intent3 = getIntent();
String lastName = intent3.getStringExtra("lastName");
Intent intent4 = getIntent();
String email = intent4.getStringExtra("email");
findViewById(R.id.buttonSignIn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String code = editTextCode.getText().toString().trim();
if (code.isEmpty() || code.length() < 6) {
editTextCode.setError("Enter valid code");
editTextCode.requestFocus();
return;
}
//verifying the code entered manually
verifyVerificationCode(code);
}
});
}
//the method is sending verification code
//the country id is concatenated
//you can take the country id as user input as well
private void sendVerificationCode(String mobile) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
"+254" + mobile,
60,
TimeUnit.SECONDS,
TaskExecutors.MAIN_THREAD,
mCallbacks);
}
//the callback to detect the verification status
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
//Getting the code sent by SMS
String code = phoneAuthCredential.getSmsCode();
//sometime the code is not detected automatically
//in this case the code will be null
//so user has to manually enter the code
if (code != null) {
editTextCode.setText(code);
//verifying the code
verifyVerificationCode(code);
}
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(VerficationPhone.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
//storing the verification id that is sent to the user
mVerificationId = s;
}
};
private void verifyVerificationCode(String code) {
//creating the credential
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, code);
//signing the user
signInWithPhoneAuthCredential(credential);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(VerficationPhone.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
//verification successful we will the profile activity
Intent intent = new Intent(VerficationPhone.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
} else {
//verification unsuccessful.. display an error message
String message = "Something is wrong, kindly add your phone number again...";
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
message = "Invalid code entered...";
}
Snackbar snackbar = Snackbar.make(findViewById(R.id.parent), message, Snackbar.LENGTH_LONG);
snackbar.setAction("Dismiss", new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
snackbar.show();
}
}
});
}
}
9-18 09:16:44.421 1180-1180/? E/SamsungIME: ET9KDB_SetKdbNum : 10
09-18 09:16:44.421 1180-1180/? E/SamsungIME: ET9KDB_GetKdbNum : 39
09-18 09:16:44.421 1180-1180/? E/SamsungIME: ET9KDB_GetPageNum : 39
09-18 09:16:44.421 1180-1180/? E/SamsungIME: ET9KDB_SetKdbNum : 10
09-18 09:16:44.421 1180-1180/? E/SamsungIME: ET9KDB_GetPageNum : 39
09-18 09:16:44.421 1180-1180/? E/SamsungIME: ET9KDB_SetMultiTapMode : 39
09-18 09:16:44.431 1180-1180/? E/SamsungIME: ET9KDB_GetKdbNum : 39
09-18 09:16:44.431 1180-1180/? E/SamsungIME: ET9KDB_GetPageNum : 39
09-18 09:16:44.431 1180-1180/? E/SamsungIME: ET9KDB_SetKdbNum : 10
09-18 09:16:44.431 1180-1180/? E/SamsungIME: ET9KDB_GetKdbNum : 39
09-18 09:16:44.431 1180-1180/? E/SamsungIME: ET9KDB_GetPageNum : 39
09-18 09:16:44.431 1180-1180/? E/SamsungIME: ET9KDB_SetKdbNum : 10
09-18 09:16:44.431 1180-1180/? E/SamsungIME: ET9KDB_GetPageNum : 39
09-18 09:16:44.431 1180-1180/? E/SamsungIME: ET9KDB_SetMultiTapMode : 39
09-18 09:16:44.521 1180-1180/? E/SamsungIME: ET9KDB_GetKdbNum : 39
09-18 09:16:44.521 1180-1180/? E/SamsungIME: ET9KDB_GetPageNum : 39
09-18 09:16:44.821 1180-1180/? E/SamsungIME: NumberFormatException
09-18 09:16:44.821 1180-1180/? E/SamsungIME: NumberFormatException
09-18 09:16:44.831 1180-1180/? E/SamsungIME: NumberFormatException
09-18 09:16:44.831 1180-1180/? E/SamsungIME: NumberFormatException
09-18 09:16:45.111 1180-1180/? E/SamsungIME: SwiftKey guide popup condition 2 : false false true true true false true true true true
09-18 09:16:47.223 755-1027/? E/Watchdog: !@Sync 2101 [09-18 09:16:47.228]
09-18 09:16:58.164 1180-1180/? E/SamsungIME: ET9KDB_SetKdbNum : 10
09-18 09:16:58.164 1180-1180/? E/SamsungIME: ET9KDB_GetKdbNum : 39
09-18 09:16:58.174 1180-1180/? E/SamsungIME: ET9KDB_GetPageNum : 39
09-18 09:16:58.174 1180-1180/? E/SamsungIME: ET9KDB_SetKdbNum : 10
09-18 09:16:58.174 1180-1180/? E/SamsungIME: ET9KDB_GetPageNum : 39
09-18 09:16:58.174 1180-1180/? E/SamsungIME: ET9KDB_SetAmbigMode : 39
09-18 09:16:58.254 1180-1180/? E/SamsungIME: ET9KDB_GetKdbNum : 39
09-18 09:16:58.254 1180-1180/? E/SamsungIME: ET9KDB_GetPageNum : 39
09-18 09:17:03.429 30457-30457/com.urbanx.urbaninsure E/ViewRootImpl: sendUserActionEvent() mView == null
09-18 0