Java Code Examples for com.google.firebase.auth.FirebaseAuth#getCurrentUser()

The following examples show how to use com.google.firebase.auth.FirebaseAuth#getCurrentUser() . 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: MainActivity.java    From white-label-event-app with Apache License 2.0 6 votes vote down vote up
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
    final FirebaseUser user = firebaseAuth.getCurrentUser();
    if (user != null) {
        LOGGER.fine("onAuthStateChanged: " + user.getUid());
        navigationHeaderView.showViewId(R.id.vg_profile);
        final TextView tv_name = (TextView) navigationHeaderView.findViewById(R.id.tv_name);
        final String name = user.getDisplayName();
        tv_name.setText(name != null ? name : "[No name]");
        final Uri photoUrl = user.getPhotoUrl();
        Glide
            .with(MainActivity.this)
            .load(photoUrl)
            .centerCrop()
            .placeholder(R.drawable.nopic)
            .into((ImageView) navigationHeaderView.findViewById(R.id.iv_pic));
        if (state.isRequestingSignin) {
            Toast.makeText(
                MainActivity.this,
                getString(R.string.msg_sign_in_thank_you, user.getDisplayName()),
                Toast.LENGTH_SHORT).show();
            state.isRequestingSignin = false;
        }
    }
    else {
        LOGGER.fine("onAuthStateChanged: signed out");
        navigationHeaderView.showViewId(R.id.button_sign_in);
        ((TextView) navigationHeaderView.findViewById(R.id.tv_name)).setText(null);
        ((ImageView) navigationHeaderView.findViewById(R.id.iv_pic)).setImageBitmap(null);
    }
}
 
Example 2
Source File: HomeActivity.java    From MangoBloggerAndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    int id = item.getItemId();

    if(id == R.id.nav_signOut) {
        PreferenceUtil.signOut(this);
        FirebaseAuth mAuth = FirebaseAuth.getInstance();
        if(mAuth.getCurrentUser() != null) {
            mAuth.signOut();
        }
        startActivity(new Intent(this, LoginActivity.class));
        finish();
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 3
Source File: MainActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void sendEmailVerification() {
    // [START send_email_verification]
    FirebaseAuth auth = FirebaseAuth.getInstance();
    FirebaseUser user = auth.getCurrentUser();

    user.sendEmailVerification()
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "Email sent.");
                    }
                }
            });
    // [END send_email_verification]
}
 
Example 4
Source File: firebaseutils.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
public static void updateuserbio(String userbio, final LinearLayout linearLayout){
    FirebaseAuth auth=FirebaseAuth.getInstance();
    FirebaseUser user=auth.getCurrentUser();
    FirebaseDatabase database = FirebaseDatabase.getInstance();

    if (user !=null) {
        DatabaseReference myRef = database.getReference("users").child(user.getUid()).child("user_bio");

        myRef.setValue(userbio).addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {

            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Snackbar.make(linearLayout,"Lamentamos mas ocorreu um erro",Snackbar.LENGTH_LONG).show();
            }
        });
    }
}
 
Example 5
Source File: firebaseutils.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
public static void setbio(final TextView bio){
    FirebaseAuth auth=FirebaseAuth.getInstance();
    FirebaseUser user=auth.getCurrentUser();
    FirebaseDatabase database = FirebaseDatabase.getInstance();

    if (user !=null){
        DatabaseReference myRef = database.getReference("users").child(user.getUid()).child("user_bio");

        myRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot.exists()){
                    bio.setText(dataSnapshot.getValue(String.class));
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }
}
 
Example 6
Source File: firebaseutils.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
public static void setuserfirstdata(final Context context, String username){
    FirebaseAuth auth=FirebaseAuth.getInstance();
    FirebaseUser user = auth.getCurrentUser();
    UserProfileChangeRequest.Builder builder = new UserProfileChangeRequest.Builder();
    builder.setDisplayName(username);
    if (user !=null){
        user.updateProfile(builder.build()).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (!task.isSuccessful()){
                    Toast.makeText(context,"Ocorreu um erro",Toast.LENGTH_LONG).show();
                }
            }
        });
    }

}
 
Example 7
Source File: AuthUiActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@NonNull
public Intent buildSignInIntent(@Nullable String link) {
    AuthUI.SignInIntentBuilder builder = AuthUI.getInstance().createSignInIntentBuilder()
            .setTheme(getSelectedTheme())
            .setLogo(getSelectedLogo())
            .setAvailableProviders(getSelectedProviders())
            .setIsSmartLockEnabled(mEnableCredentialSelector.isChecked(),
                    mEnableHintSelector.isChecked());

    if (mCustomLayout.isChecked()) {
        AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout
                .Builder(R.layout.auth_method_picker_custom_layout)
                .setGoogleButtonId(R.id.custom_google_signin_button)
                .setEmailButtonId(R.id.custom_email_signin_clickable_text)
                .setTosAndPrivacyPolicyId(R.id.custom_tos_pp)
                .build();

        builder.setTheme(R.style.CustomTheme);
        builder.setAuthMethodPickerLayout(customLayout);
    }

    if (getSelectedTosUrl() != null && getSelectedPrivacyPolicyUrl() != null) {
        builder.setTosAndPrivacyPolicyUrls(
                getSelectedTosUrl(),
                getSelectedPrivacyPolicyUrl());
    }

    if (link != null) {
        builder.setEmailLink(link);
    }

    FirebaseAuth auth = FirebaseAuth.getInstance();

    if (auth.getCurrentUser() != null && auth.getCurrentUser().isAnonymous()) {
        builder.enableAnonymousUsersAutoUpgrade();
    }

    return builder.build();
}
 
Example 8
Source File: PostsAdapter.java    From Hify with MIT License 5 votes vote down vote up
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    mFirestore = FirebaseFirestore.getInstance();
    mCurrentUser = mAuth.getCurrentUser();
    View view= LayoutInflater.from(context).inflate(R.layout.item_feed_post,parent,false);
    return new ViewHolder(view);
}
 
Example 9
Source File: FavSessionButtonManager.java    From white-label-event-app with Apache License 2.0 5 votes vote down vote up
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
    user = firebaseAuth.getCurrentUser();
    if (user != null) {
        startListeningFavorites();
    }
    else {
        stopListeningFavorites();
    }
}
 
Example 10
Source File: LoginPresenter.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
    if (isAttached()) {
        FirebaseUser user = firebaseAuth.getCurrentUser();
        if (user != null) {
            getView().onFirebaseUser(user);
        } else {
            Logger.e();
        }
    }
}
 
Example 11
Source File: firebaseutils.java    From LuxVilla with Apache License 2.0 5 votes vote down vote up
public static void removelike(String id){
    String uid="";
    FirebaseAuth auth=FirebaseAuth.getInstance();
    FirebaseUser user=auth.getCurrentUser();
    if (user != null){
        uid=user.getUid();
    }
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("users").child(uid).child("likes");
    myRef.child("heart"+id).removeValue();
}
 
Example 12
Source File: firebaseutils.java    From LuxVilla with Apache License 2.0 5 votes vote down vote up
public static void setlike(String id){
    String uid="";
    FirebaseAuth auth=FirebaseAuth.getInstance();
    FirebaseUser user=auth.getCurrentUser();
    if (user != null){
        uid=user.getUid();
    }
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("users").child(uid).child("likes");
    myRef.child("heart"+id).child("liked").setValue("true");
}
 
Example 13
Source File: SignInUI.java    From stockita-point-of-sale with MIT License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Check current user is already signed in or not
    FirebaseAuth auth = FirebaseAuth.getInstance();
    boolean isSignIn = auth.getCurrentUser() != null;


    if (!isSignIn) {

        // FirebaseUI line of code
        startActivityForResult(
                AuthUI.getInstance()
                        .createSignInIntentBuilder()
                        .setIsSmartLockEnabled(!BuildConfig.DEBUG)
                        .setProviders(AuthUI.EMAIL_PROVIDER, AuthUI.GOOGLE_PROVIDER, AuthUI.FACEBOOK_PROVIDER)
                        .setTheme(R.style.AppTheme)
                        .build(), RC_SIGN_IN);


    }

    if (isSignIn) {
        // Go directly to the main activity.
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

}
 
Example 14
Source File: PostActivity.java    From Simple-Blog-App with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_post);

    bindViews();

    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    mCurrentUser = mAuth.getCurrentUser();
    mDatabaseUSer = FirebaseDatabase.getInstance().getReference().child("Users").child(mCurrentUser.getUid());

    clickEvents();

}
 
Example 15
Source File: MainActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
private void gamesGetUserInfo() {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();

    // [START games_get_user_info]
    FirebaseUser user = mAuth.getCurrentUser();
    String playerName = user.getDisplayName();

    // 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();
    // [END games_get_user_info]
}
 
Example 16
Source File: MainActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
public void sendEmailVerificationWithContinueUrl() {
    // [START send_email_verification_with_continue_url]
    FirebaseAuth auth = FirebaseAuth.getInstance();
    FirebaseUser user = auth.getCurrentUser();

    String url = "http://www.example.com/verify?uid=" + user.getUid();
    ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder()
            .setUrl(url)
            .setIOSBundleId("com.example.ios")
            // The default for this is populated with the current android package name.
            .setAndroidPackageName("com.example.android", false, null)
            .build();

    user.sendEmailVerification(actionCodeSettings)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "Email sent.");
                    }
                }
            });

    // [END send_email_verification_with_continue_url]
    // [START localize_verification_email]
    auth.setLanguageCode("fr");
    // To apply the default app language instead of explicitly setting it.
    // auth.useAppLanguage();
    // [END localize_verification_email]
}
 
Example 17
Source File: AuthUiActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    FirebaseAuth auth = FirebaseAuth.getInstance();
    if (auth.getCurrentUser() != null && getIntent().getExtras() == null) {
        startSignedInActivity(null);
        finish();
    }
}
 
Example 18
Source File: InitialActivity.java    From cannonball-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FirebaseAuth auth = FirebaseAuth.getInstance();

    if (auth.getCurrentUser() != null) {
        startThemeActivity();
    } else {
        startLoginActivity();
    }
}
 
Example 19
Source File: AuthOperationManager.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
public boolean canUpgradeAnonymous(FirebaseAuth auth, FlowParameters flowParameters) {
    return flowParameters.isAnonymousUpgradeEnabled() && auth.getCurrentUser() != null &&
            auth.getCurrentUser().isAnonymous();
}
 
Example 20
Source File: FirebaseOpsHelper.java    From CourierApplication with Mozilla Public License 2.0 4 votes vote down vote up
private FirebaseUser getCurrentUser() {
    FirebaseAuth auth = FirebaseAuth.getInstance();
    return auth.getCurrentUser();
}