I'm doing an android application with registration and login, and one of the parties is password recovery. For this process I have done that when the mail is sent a sms with a code to the related number, having this service thanks to FIREBASE, the problem is that at the beginning it was without errors and suddenly the method does not go and gives me the error of the title when pressing the button that must do all the actions of connection with firebase, sending of sms and everything related. Next I will put the code and the error.
package com.example.alex.proyecto;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
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.FirebaseException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import org.json.JSONObject;
import java.util.concurrent.TimeUnit;
import cz.msebera.android.httpclient.Header;
public class PassActivity extends AppCompatActivity {
FirebaseAuth auth;
EditText correo,codigo;
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallBack;
String codigoVerificacion;
String numero;
String url = "http://proyectokiriki.000webhostapp.com/devolverCorreo.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pantalla_pass);
correo = (EditText) findViewById(R.id.textoCorreo);
codigo = (EditText) findViewById(R.id.textoCodigo);
auth = FirebaseAuth.getInstance();
mCallBack = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
}
@Override
public void onVerificationFailed(FirebaseException e) {
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
codigoVerificacion = s;
Toast.makeText(getApplicationContext(), "Codigo enviado.",Toast.LENGTH_LONG).show();
}
};
}
public void enviarSMS(View v) {
String correoN = correo.getText().toString().trim();
if (correoN.isEmpty()) {
Toast.makeText(getApplicationContext(), "Debes introducir un correo.", Toast.LENGTH_LONG).show();
} else {
AsyncHttpClient cliente = new AsyncHttpClient();
RequestParams rp = new RequestParams();
rp.put("correo",correoN);
cliente.post(url, rp, new JsonHttpResponseHandler(){
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
String respuesta = response.toString();
Gson gson = new Gson();
Correo correoSMS = gson.fromJson(respuesta, Correo.class);
numero = correoSMS.getUsuario().get(0).getTelefono();
}
});
numero = "+34" + numero;
PhoneAuthProvider.getInstance().verifyPhoneNumber(numero, 60, TimeUnit.SECONDS, this, mCallBack);
}
}
public void singInWithPhone(PhoneAuthCredential credential){
auth.signInWithCredential(credential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Intent pass = new Intent(getApplicationContext(),CambioPassActivity.class);
String correoN = correo.getText().toString().trim();
pass.putExtra("correo",correoN);
finish();
startActivity(pass);
}
}
});
}
public void verificar(View v){
String codigoIntroducido = codigo.getText().toString();
if(!codigoVerificacion.equalsIgnoreCase("")){
verificarNumero(codigoVerificacion,codigoIntroducido);
}
}
public void verificarNumero(String codigoVerificacion, String codigoIntroducido){
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(codigoVerificacion, codigoIntroducido);
singInWithPhone(credential);
}
}
Next I put what comes out when I press the button that should send the sms:
2018-11-05 02:06:19.384 6040-6040/com.example.alex.proyecto
W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzal@6a4856b
2018-11-05 02:06:19.390 3413-3621/? D/DnsProxyListener: DNSDBG::dns addrinfo af 2
2018-11-05 02:06:19.416 11534-11988/? W/FirebaseAuth: [PhoneVerificationSession] PhoneVerificationSession constructor
2018-11-05 02:06:19.419 11534-13980/? W/FirebaseAuth: [PhoneNumberAuthPostProcessor] postProcess starts
2018-11-05 02:06:19.430 3787-3949/? D/ConnectivityService: filterNetworkStateForUid() uid: 10024 networkInfo: [type: WIFI[] - WIFI, state: CONNECTED/CONNECTED, reason: (unspecified), extra: "WW 42", failover: false, available: true, roaming: false, metered: false]
2018-11-05 02:06:19.445 11534-23086/? I/AuthChimeraService: Executing request: ProxyRequest[ url: https://www.googleapis.com/identitytoolkit/v3/relyingparty/sendVerificationCode?alt=proto&key=AIzaSyCWF-lLJGTp6i-hRIadiNdEhXk7dZ5JXGY, method: 1 ]
2018-11-05 02:06:19.467 11534-31778/? I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
2018-11-05 02:06:19.467 11534-31778/? I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
2018-11-05 02:06:19.640 11534-31778/? E/Volley: [110535] BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/identitytoolkit/v3/relyingparty/sendVerificationCode?alt=proto&key=AIzaSyCWF-lLJGTp6i-hRIadiNdEhXk7dZ5JXGY
2018-11-05 02:06:19.641 11534-23086/? I/AuthChimeraService: Error description received from server: INVALID_PHONE_NUMBER : Invalid format.
2018-11-05 02:06:19.641 11534-11982/? W/FirebaseAuth: [PhoneVerificationSession] onFailure
2018-11-05 02:06:19.820 11534-13980/? W/FirebaseAuth: [PhoneNumberAuthPostProcessor] postProcess ends
2018-11-05 02:06:19.993 6040-6040/com.example.alex.proyecto V/AsyncHttpRH: Progress 494 from 1 (49400%)
2018-11-05 02:06:19.997 6040-6040/com.example.alex.proyecto W/JsonHttpRH: onFailure(int, Header[], String, Throwable) was not overriden, but callback was received
org.json.JSONException: Response cannot be parsed as JSON data
at com.loopj.android.http.JsonHttpResponseHandler$1$1.run(JsonHttpResponseHandler.java:158)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)