-2
I’m developing an app that uses Firebase. I had a lot of problems W/System: Ignoring header X-Firebase-Locale because its value was null. Thinking this is the case I’ve invested a lot of time trying to solve this.
I noticed that it even connects if stay the login screen for 30 seconds it ends up logging in firebase. Very slow.
When I did a 4G test and it worked really well and really fast. I took any other application from my phone as in the case Glotify should use google services, to my surprise also got slow and did not connect.
Again I took the wifi , tried again in this app in question and worked very fast several times. It is not my wifi from home not because I went elsewhere and also did not work.
Good was the same Internet operator A NET.
I’ll even put the code here, but how it works for 4G, and all right. And the other application of a large company (glorify) also does not work on login.
The question comes: It is in google, or in the operator?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_login );
mAuth = FirebaseAuth.getInstance();
mAuth.getUid ();
try {
if ( mAuth != null ) {
String uid = mAuth.getUid ();
}
} catch ( Exception e ) {
e.printStackTrace ( );
}
// Configure Google Sign In
gso = new GoogleSignInOptions.Builder( GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
editEmail = findViewById( R.id.email );
editSenha = findViewById( R.id.password );
btnCancelarLogin = findViewById (R.id.btnCancelarLogin );
btnCancelarLogin.setOnClickListener (this);
btnGoogleConection = findViewById (R.id.btnGoogleConection );
btnGoogleConection.setOnClickListener (this);
btnForgotPassword = findViewById (R.id.btnEsqueci_Senha );
progressDialog = new ProgressDialog( this );
// Create token receiver (for demo purposes only)
mTokenReceiver = new TokenBroadcastReceiver() {
@Override
public void onNewToken(String token) {
Log.d( TAG, "onNewToken:" + token );
setCustomToken( token );
}
};
}
private void logarUsuario(){
final String email = editEmail.getEditText().getText().toString().trim();
String senha = editSenha.getEditText().getText().toString().trim();
if (!validateForm()) {
return;
}
try {
progressDialog.setMessage( getString( R.string.iniciando_login) );
progressDialog.show();
//Consultar se leader existe
mAuth.signInWithEmailAndPassword( email, senha )
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener <AuthResult> () {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
//checando sucesso
if(task.isSuccessful()){
int pos = email.indexOf("@");
String user = email.substring(0,pos);
Toast.makeText( LoginActivity.this, getString( R.string.logado_sucesso),Toast.LENGTH_SHORT).show();
FirebaseUser currentUser = mAuth.getCurrentUser();
updateUI(currentUser);
editEmail.getEditText().setText("");
editSenha.getEditText().setText("");
Intent home = new Intent( LoginActivity.this, HomeActivity.class );
startActivity( home );
// startSignIn();
}else{ //se houver colisão de mesmo usuário
if (task.getException() instanceof FirebaseAuthUserCollisionException){
Toast.makeText( LoginActivity.this, getString( R.string.usuario_existe),Toast.LENGTH_SHORT).show();
HomeActivity.Logado = false;
}else{
Toast.makeText( LoginActivity.this,getString( R.string.falha_login), Toast.LENGTH_LONG ).show();
HomeActivity.Logado = false;
}
}
progressDialog.dismiss();
}
} );
} catch ( Exception e ) {
e.printStackTrace ( );
}
}
@Override
public void onClick(View v) {
int id = v.getId ( );
if ( id == R.id.btnEnviarLogin ) {
logarUsuario ( );
} else if ( id == R.id.btnCancelarLogin ) {
finishAffinity ( );
}else if ( id == R.id.btnEsqueci_Senha){
Intent remember = new Intent( LoginActivity.this, RememberActivity.class );
startActivity( remember );
}else if (id == R.id.btnRegistro){
Intent register= new Intent( LoginActivity.this, RegisterActivity.class );
startActivity( register );
}else if(id == R.id.btnGoogleConection){
signIn();
}
}
public static void updateUI(FirebaseUser user){
if (user != null) {
HomeActivity.Logado = true;
String name = user.getDisplayName();
String email = user.getEmail();
Uri photoUrl = user.getPhotoUrl();
// Check if user's email is verified
boolean emailVerified = user.isEmailVerified();
// The user's ID, unique to the Firebase project. Do NOT use this value to
// authenticate with your backend server, if you have one. Use
// FirebaseUser.getIdToken() instead.
String uid = user.getUid();
} else {
HomeActivity.Logado = false;
}
}
//start google conection
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
Log.d(TAG, "firebaseAuthWithGoogle:" + account.getId());
firebaseAuthWithGoogle(account.getIdToken());
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e);
// ...
}
}
}
private void firebaseAuthWithGoogle(String idToken) {
AuthCredential credential = GoogleAuthProvider.getCredential(idToken, null);
progressDialog.setMessage( getString( R.string.iniciando_login) );
progressDialog.show();
mAuth.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
Log.d(TAG, "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
Intent home = new Intent( LoginActivity.this, HomeActivity.class );
progressDialog.dismiss();
startActivity( home );
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
updateUI(null);
}
// ...
}
});
}
//finish google connection
@Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
updateUI(currentUser);
}
It’s a personal problem that I don’t know how to solve. Someone knows about it?
– Fabiano de Souza Pereira
By the negatives I’m getting; I think I should tell my client to use the app only on 4G then. If a moderator would be kind enough to tell me what’s wrong with my question, I’d appreciate it.
– Fabiano de Souza Pereira