-1

I am using Firebase Google SignIn in my Android application and I want to check the gender of every user, as the application is only for the females to use !!

Currently work is like this

// Initialize Firebase Auth
        mFirebaseAuth = FirebaseAuth.getInstance();
        mFirebaseUser = mFirebaseAuth.getCurrentUser();

        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(FirebaseAuth firebaseAuth) {
                if (mFirebaseUser == null) {
                    startActivity(new Intent(getApplicationContext(), SignActivity.class));
                    finish();
                    return;
                } else {
                    if (mFirebaseUser.getPhotoUrl() != null) {
                        Glide.with(HomeActivity.this)
                                .load(mFirebaseUser.getPhotoUrl().toString())
                                .asBitmap()
                                .into(new SimpleTarget<Bitmap>(100,100) {
                                    @Override
                                    public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                                        bitmap = resource;
                                    }
                                });
                    }
                }
            }
        };

        // Configure Google Sign In
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();
        GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this ,this)
                .addApi(Auth.GOOGLE_SIGN_IN_API , gso)
                .build();
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Akshay Nandwana
  • 1,260
  • 11
  • 18

1 Answers1

0

Unfortunately, Firebase doesn't have any built-in functionality to get the user's gender from your mFirebaseUser object. You would have to retrieve these data from each of the providers yourself.

Take a look at this post, to see how can the gender be extracted.

And also, take a look at Accessing Google APIs.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193