(Solved) Firebase Google only connects in apps by 4G, no wifi

Asked

Viewed 46 times

-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?

  • 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.

2 answers

-1


Good going on the English stackoverflow in the post Couldn’t connect to firebase database via WIFI but Connects fine with 4G mobile network. Strange Issue I saw in a reply

The Solution for me was to replace the internet service Provider SIM card as I’m using 4G access point in my home.

So I kept thinking about my case, and I went to another network, connected on wifi and it worked. Then I realized it could be something on my modem. I restarted my modem and my app returned to connect on Firebase on my wifi.

In the other place that also did not work I believe that it should be restarted the modem from there too. (Obs. remembered that the net of them sometimes hangs).

I do not know why this error in the modem, but for me it solved.

Restart the Modem worked!

For those who have denied my question a hug.

-3

Firstly, there is nothing wrong with your question. I came across the same problem as you using Firebase Realtime Database and Firebaseuth. In my case it did not work with the network 4g , with the wi-fi yes , and when used with the 4g and a VPN, too. In my opinion , it is a problem of Firebase itself with the configuration of some types of routers , which would explain this behavior. When using a VPN , the connection goes through other servers , using other routers , and occurs naturally. Basically, there is nothing that can be done in the application code to circumvent this type of behavior in Firebase.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.