com.google.firebase.auth.UserInfo Java Examples

The following examples show how to use com.google.firebase.auth.UserInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogoutHelper.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public static void signOut(GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        ProfileInteractor.getInstance(fragmentActivity.getApplicationContext())
                .removeRegistrationToken(FirebaseInstanceId.getInstance().getToken(), user.getUid());

        for (UserInfo profile : user.getProviderData()) {
            String providerId = profile.getProviderId();
            logoutByProvider(providerId, mGoogleApiClient, fragmentActivity);
        }
        logoutFirebase(fragmentActivity.getApplicationContext());
    }

    if (clearImageCacheAsyncTask == null) {
        clearImageCacheAsyncTask = new ClearImageCacheAsyncTask(fragmentActivity.getApplicationContext());
        clearImageCacheAsyncTask.execute();
    }
}
 
Example #2
Source File: LogoutHelper.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public static void signOut(GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        ProfileInteractor.getInstance(fragmentActivity.getApplicationContext())
                .removeRegistrationToken(FirebaseInstanceId.getInstance().getToken(), user.getUid());

        for (UserInfo profile : user.getProviderData()) {
            String providerId = profile.getProviderId();
            logoutByProvider(providerId, mGoogleApiClient, fragmentActivity);
        }
        logoutFirebase(fragmentActivity.getApplicationContext());
    }

    if (clearImageCacheAsyncTask == null) {
        clearImageCacheAsyncTask = new ClearImageCacheAsyncTask(fragmentActivity.getApplicationContext());
        clearImageCacheAsyncTask.execute();
    }
}
 
Example #3
Source File: MainActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void getProviderData() {
    // [START get_provider_data]
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        for (UserInfo profile : user.getProviderData()) {
            // Id of the provider (ex: google.com)
            String providerId = profile.getProviderId();

            // UID specific to the provider
            String uid = profile.getUid();

            // Name, email address, and profile photo Url
            String name = profile.getDisplayName();
            String email = profile.getEmail();
            Uri photoUrl = profile.getPhotoUrl();
        }
    }
    // [END get_provider_data]
}
 
Example #4
Source File: AuthUI.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials, not
 * for saving since we don't have access to the password.
 */
private static List<Credential> getCredentialsFromFirebaseUser(@NonNull FirebaseUser user) {
    if (TextUtils.isEmpty(user.getEmail()) && TextUtils.isEmpty(user.getPhoneNumber())) {
        return Collections.emptyList();
    }

    List<Credential> credentials = new ArrayList<>();
    for (UserInfo userInfo : user.getProviderData()) {
        if (FirebaseAuthProvider.PROVIDER_ID.equals(userInfo.getProviderId())) {
            continue;
        }

        String type = ProviderUtils.providerIdToAccountType(userInfo.getProviderId());
        if (type == null) {
            // Since the account type is null, we've got an email credential. Adding a fake
            // password is the only way to tell Smart Lock that this is an email credential.
            credentials.add(CredentialUtils.buildCredentialOrThrow(user, "pass", null));
        } else {
            credentials.add(CredentialUtils.buildCredentialOrThrow(user, null, type));
        }
    }

    return credentials;
}
 
Example #5
Source File: Userprofile.java    From LuxVilla with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_userprofile);

    toolbarLayout= findViewById(R.id.tbprofile);
    toolbar= findViewById(R.id.barprofileactivity);
    toolbar.setNavigationIcon(R.mipmap.ic_arrow_back_white_24dp);
    setSupportActionBar(toolbar);
    profileimage= findViewById(R.id.imgprofile);
    mAuth=FirebaseAuth.getInstance();
    user=mAuth.getCurrentUser();
    if (user !=null) {
        for (UserInfo userdata: user.getProviderData()) {

            profileDisplayName=userdata.getDisplayName();
            toolbarLayout.setTitle(profileDisplayName);
            profilePhotoUrl=userdata.getPhotoUrl();
        }
        if (profilePhotoUrl !=null){
            String image=profilePhotoUrl.toString();
            Picasso.with(Userprofile.this)
                    .load(image)
                    .fit()
                    .into(profileimage);
        }else{
            profileimage.setImageDrawable(ContextCompat.getDrawable(Userprofile.this,R.drawable.nouserimage));
        }
    }
    tbs= findViewById(R.id.profiletabs);
    tbs.setSelectedTabIndicatorColor(ContextCompat.getColor(Userprofile.this,R.color.colorAccent));
    vwpgr= findViewById(R.id.profilevpgr);
    adaptadortabs adaptador=new adaptadortabs(getSupportFragmentManager());
    vwpgr.setAdapter(adaptador);
    tbs.setupWithViewPager(vwpgr);

}
 
Example #6
Source File: Editprofile.java    From LuxVilla with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_editprofile);

    toolbar= findViewById(R.id.barprofileactivity);
    toolbar.setTitle("Editar perfil");
    toolbar.setNavigationIcon(R.mipmap.ic_arrow_back_white_24dp);
    setSupportActionBar(toolbar);

    linearLayout= findViewById(R.id.linearLayouteditprofile);
    textInputLayoutusername= findViewById(R.id.text_input_username);

    editTextusername= findViewById(R.id.edittextusername);
    editTextuserbio= findViewById(R.id.edittextbio);

    mAuth=FirebaseAuth.getInstance();

    user=mAuth.getCurrentUser();
    if (user !=null){
        for (UserInfo userdata: user.getProviderData()) {
            String userprovider=userdata.getProviderId();

            if (userprovider.equals("google.com")){
                textInputLayoutusername.setVisibility(View.GONE);
            }
        }
    }
}
 
Example #7
Source File: SignedInActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private void populateProfile(@Nullable IdpResponse response) {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user.getPhotoUrl() != null) {
        GlideApp.with(this)
                .load(user.getPhotoUrl())
                .fitCenter()
                .into(mUserProfilePicture);
    }

    mUserEmail.setText(
            TextUtils.isEmpty(user.getEmail()) ? "No email" : user.getEmail());
    mUserPhoneNumber.setText(
            TextUtils.isEmpty(user.getPhoneNumber()) ? "No phone number" : user.getPhoneNumber());
    mUserDisplayName.setText(
            TextUtils.isEmpty(user.getDisplayName()) ? "No display name" : user.getDisplayName());

    if (response == null) {
        mIsNewUser.setVisibility(View.GONE);
    } else {
        mIsNewUser.setVisibility(View.VISIBLE);
        mIsNewUser.setText(response.isNewUser() ? "New user" : "Existing user");
    }

    List<String> providers = new ArrayList<>();
    if (user.getProviderData().isEmpty()) {
        providers.add(getString(R.string.providers_anonymous));
    } else {
        for (UserInfo info : user.getProviderData()) {
            switch (info.getProviderId()) {
                case GoogleAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_google));
                    break;
                case FacebookAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_facebook));
                    break;
                case TwitterAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_twitter));
                    break;
                case EmailAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_email));
                    break;
                case PhoneAuthProvider.PROVIDER_ID:
                    providers.add(getString(R.string.providers_phone));
                    break;
                case EMAIL_LINK_PROVIDER:
                    providers.add(getString(R.string.providers_email_link));
                    break;
                case FirebaseAuthProvider.PROVIDER_ID:
                    // Ignore this provider, it's not very meaningful
                    break;
                default:
                    providers.add(info.getProviderId());
            }
        }
    }

    mEnabledProviders.setText(getString(R.string.used_providers, providers));
}