Java Code Examples for com.google.firebase.auth.FirebaseUser

The following examples show how to use com.google.firebase.auth.FirebaseUser. These examples are extracted from open source projects. 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 Project: snippets-android   Source File: MainActivity.java    License: Apache License 2.0 8 votes vote down vote up
public void getUserProfile() {
    // [START get_user_profile]
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        // Name, email address, and profile photo Url
        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();
    }
    // [END get_user_profile]
}
 
Example 2
Source Project: Password-Storage   Source File: LoginActivity.java    License: MIT License 7 votes vote down vote up
private void checkIfEmailVerified(){
    FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
    if (user.isEmailVerified()){
        Toast.makeText(getApplicationContext(),
                R.string.login_successful_login, Toast.LENGTH_SHORT).show();
        Intent sendToLogout = new Intent(getApplicationContext(),
                MainActivity.class);
        sendToLogout.putExtra("email", str_Email);
        startActivity(sendToLogout);
    } else {
        Toast.makeText(getApplicationContext(),
                R.string.login_email_notverified,Toast.LENGTH_SHORT).show();
    }
}
 
Example 3
Source Project: protrip   Source File: MainActivity.java    License: MIT License 7 votes vote down vote up
private void onSignedInInitialize(FirebaseUser firebaseUser) {

        //Firebase Auth
        User user = new User(firebaseUser.getDisplayName(),
                firebaseUser.getPhotoUrl(),
                firebaseUser.getEmail(), firebaseUser.getUid());
        mUsername = user.getUsername();
        mUserAvatarUrl = user.getAvatarUrl();
        mUserEmail = user.getEmailId();
        mUid = user.getUid();
        tvUserName.setText(mUsername);
        tvUserEmail.setVisibility(View.VISIBLE);
        tvUserEmail.setText(mUserEmail);
        logoutItem.setVisible(true);
        favoritesItem.setVisible(true);
        if (mUserAvatarUrl != null) {
            Picasso.with(this).load(mUserAvatarUrl).
                    placeholder(R.drawable.ic_account_circle_white_24dp).
                    transform(new CircleTransform()).
                    fit().
                    into(ivAvatar);
        }


    }
 
Example 4
Source Project: custom-auth-samples   Source File: MainActivity.java    License: Apache License 2.0 7 votes vote down vote up
/**
 * Update UI based on Firebase's current user. Show Login Button if not logged in.
 */
private void updateUI() {
    FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
    if (currentUser != null) {
        binding.setCurrentUser(currentUser);
        if (currentUser.getPhotoUrl() != null) {
            Glide.with(this)
                    .load(currentUser.getPhotoUrl())
                    .into(imageView);
        }
        loginButton.setVisibility(View.INVISIBLE);
        loggedInView.setVisibility(View.VISIBLE);
        logoutButton.setVisibility(View.VISIBLE);
    } else {
        loginButton.setVisibility(View.VISIBLE);
        loggedInView.setVisibility(View.INVISIBLE);
        logoutButton.setVisibility(View.INVISIBLE);
    }
}
 
Example 5
Source Project: rxfirebase   Source File: RxFirebaseAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSignInWithCredential() {
    mockSuccessfulAuthResult();

    when(mockFirebaseAuth.signInWithCredential(mockAuthCredential))
            .thenReturn(mockAuthResultTask);

    TestObserver<FirebaseUser> obs = TestObserver.create();

    RxFirebaseAuth
            .signInWithCredential(mockFirebaseAuth, mockAuthCredential)
            .subscribe(obs);

    callOnComplete(mockAuthResultTask);
    obs.dispose();

    // Ensure no more values are emitted after unsubscribe
    callOnComplete(mockAuthResultTask);

    obs.assertComplete();
    obs.assertValueCount(1);
}
 
Example 6
private void getUserRole(FirebaseUser user) {
    final DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference();
    dbRef.child("users").child(user.getUid()).addListenerForSingleValueEvent(
            new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if(dataSnapshot.exists()) {
                        String role = String.valueOf(dataSnapshot.child("role").getValue());
                        if(role.equals("courier")) {
                            mCurrentOrderInteractor.onUserRoleReceived(true);
                        } else {
                            mCurrentOrderInteractor.onUserRoleReceived(false);
                        }
                    }
                }
                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            }
    );
}
 
Example 7
private void initVariable() {
    @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    sdf.setTimeZone(TimeZone.getTimeZone("IST"));
    mTime = sdf.format(new Date());

    // Getting the date
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);
    mDate = day + "-" + month + "-" + year;

    mMessage = mEmojiconEditText.getText().toString();

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    uid = Objects.requireNonNull(user).getUid();


    if (Objects.requireNonNull(user).getPhotoUrl() != null) {
        mProfilePic = Objects.requireNonNull(user.getPhotoUrl()).toString();
    }
}
 
Example 8
Source Project: rxfirebase   Source File: RxFirebaseUserTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testUnlink() {
    mockSuccessfulAuthResult();
    when(mockFirebaseUser.unlink("provider"))
            .thenReturn(mockAuthTaskResult);

    TestObserver<FirebaseUser> obs = TestObserver.create();

    RxFirebaseUser.unlink(mockFirebaseUser, "provider")
            .subscribe(obs);

    callOnComplete(mockAuthTaskResult);
    obs.dispose();

    // Ensure no more values are emitted after unsubscribe
    callOnComplete(mockAuthTaskResult);

    obs.assertComplete();
    obs.assertValueCount(1);
}
 
Example 9
Source Project: social-app-android   Source File: LoginActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initFirebaseAuth() {
    mAuth = FirebaseAuth.getInstance();

    if (mAuth.getCurrentUser() != null) {
        LogoutHelper.signOut(mGoogleApiClient, this);
    }

    mAuthListener = firebaseAuth -> {
        final FirebaseUser user = firebaseAuth.getCurrentUser();
        if (user != null) {
            // Profile is signed in
            LogUtil.logDebug(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            presenter.checkIsProfileExist(user.getUid());
            setResult(RESULT_OK);
        } else {
            // Profile is signed out
            LogUtil.logDebug(TAG, "onAuthStateChanged:signed_out");
        }
    };
}
 
Example 10
Source Project: rxfirebase   Source File: RxFirebaseAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSignInWithCredential_NotSuccessful() {
    mockNotSuccessfulResult(new IllegalStateException());

    when(mockFirebaseAuth.signInWithCredential(mockAuthCredential))
            .thenReturn(mockAuthResultTask);

    TestObserver<FirebaseUser> obs = TestObserver.create();

    RxFirebaseAuth
            .signInWithCredential(mockFirebaseAuth, mockAuthCredential)
            .subscribe(obs);

    callOnComplete(mockAuthResultTask);
    obs.dispose();

    // Ensure no more values are emitted after unsubscribe
    callOnComplete(mockAuthResultTask);

    obs.assertError(IllegalStateException.class);
    obs.assertNoValues();
}
 
Example 11
Source Project: rxfirebase   Source File: RxFirebaseAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSignInWithCustomToken_NotSuccessful() {
    mockNotSuccessfulResult(new IllegalStateException());

    when(mockFirebaseAuth.signInWithCustomToken("custom_token"))
            .thenReturn(mockAuthResultTask);

    TestObserver<FirebaseUser> obs = TestObserver.create();

    RxFirebaseAuth
            .signInWithCustomToken(mockFirebaseAuth, "custom_token")
            .subscribe(obs);

    callOnComplete(mockAuthResultTask);
    obs.dispose();

    // Ensure no more values are emitted after unsubscribe
    callOnComplete(mockAuthResultTask);

    obs.assertError(IllegalStateException.class);
    obs.assertNoValues();
}
 
Example 12
Source Project: LuxVilla   Source File: firebaseutils.java    License: 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 13
Source Project: social-app-android   Source File: LogoutHelper.java    License: 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 14
Source Project: quickstart-android   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void updateUI(FirebaseUser user) {
    // Signed in or Signed out
    if (user != null) {
        binding.layoutSignin.setVisibility(View.GONE);
        binding.layoutStorage.setVisibility(View.VISIBLE);
    } else {
        binding.layoutSignin.setVisibility(View.VISIBLE);
        binding.layoutStorage.setVisibility(View.GONE);
    }

    // Download URL and Download button
    if (mDownloadUrl != null) {
        binding.pictureDownloadUri.setText(mDownloadUrl.toString());
        binding.layoutDownload.setVisibility(View.VISIBLE);
    } else {
        binding.pictureDownloadUri.setText(null);
        binding.layoutDownload.setVisibility(View.GONE);
    }
}
 
Example 15
Source Project: custom-auth-samples   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void updateUI() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    if (user == null) {
        mLineLoginButton.setVisibility(View.VISIBLE);
        mLoggedInView.setVisibility(View.INVISIBLE);
    } else {
        Log.d(TAG, "UID = " + user.getUid());
        Log.d(TAG, "Provider ID = " + user.getProviderId());

        mLineLoginButton.setVisibility(View.INVISIBLE);
        mLoggedInView.setVisibility(View.VISIBLE);

        mDisplayNameText.setText(user.getDisplayName());
        if (user.getPhotoUrl() != null) {
            mProfileImageView.setImageUrl(user.getPhotoUrl().toString(), mImageLoader);
        }

    }
}
 
Example 16
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    btnFBLogout = findViewById(R.id.btnlogout);
    tvid = findViewById(R.id.tvId);

    mAuth = FirebaseAuth.getInstance();

    FirebaseUser user = mAuth.getCurrentUser();
    //String id = user.
   // tvid.setText(id);

    btnFBLogout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mAuth.signOut();//firebase
            LoginManager.getInstance().logOut();//facebook
            updateUI();

        }
    });
}
 
Example 17
Source Project: LuxVilla   Source File: firebaseutils.java    License: 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 18
Source Project: endpoints-samples   Source File: TwitterLoginActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void updateUI(FirebaseUser user) {
    hideProgressDialog();
    if (user != null) {
        mStatusTextView.setText(getString(R.string.twitter_status_fmt, user.getDisplayName()));
        mDetailTextView.setText(getString(R.string.firebase_status_fmt, user.getUid()));

        findViewById(R.id.button_twitter_login).setVisibility(View.GONE);
        findViewById(R.id.button_twitter_signout).setVisibility(View.VISIBLE);
    } else {
        mStatusTextView.setText(R.string.signed_out);
        mDetailTextView.setText(null);

        findViewById(R.id.button_twitter_login).setVisibility(View.VISIBLE);
        findViewById(R.id.button_twitter_signout).setVisibility(View.GONE);
    }
}
 
Example 19
Source Project: rxfirebase   Source File: RxFirebaseUserTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLinkWithCredential_notSuccessful() {
    mockNotSuccessfulAuthResult(new IllegalStateException());
    when(mockFirebaseUser.linkWithCredential(mockAuthCredential))
            .thenReturn(mockAuthTaskResult);

    TestObserver<FirebaseUser> obs = TestObserver.create();

    RxFirebaseUser.linkWithCredential(mockFirebaseUser, mockAuthCredential)
            .subscribe(obs);

    callOnComplete(mockAuthTaskResult);
    obs.dispose();

    obs.assertError(IllegalStateException.class);
}
 
Example 20
Source Project: gdx-fireapp   Source File: AuthPromiseConsumerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setup() throws Exception {
    super.setup();
    PowerMockito.mockStatic(FirebaseAuth.class);
    FirebaseAuth firebaseAuth = PowerMockito.mock(FirebaseAuth.class);
    Mockito.when(firebaseAuth.getCurrentUser()).thenReturn(Mockito.mock(FirebaseUser.class));
    Mockito.when(FirebaseAuth.getInstance()).thenReturn(firebaseAuth);
    task = Mockito.mock(Task.class);
    Mockito.when(task.addOnCompleteListener(Mockito.any(OnCompleteListener.class))).thenAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((OnCompleteListener) invocation.getArgument(0)).onComplete(task);
            return null;
        }
    });
}
 
Example 21
Source Project: Stayfit   Source File: LoginActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initializeUserInfo() {
    FirebaseUser user = mAuth.getCurrentUser();
    String userId = user.getUid();

    DatabaseReference usersRef = mDatabase.child("Users");
    DatabaseReference stepsRef = mDatabase.child("Steps");
    DatabaseReference caloriesRef = mDatabase.child("Calories");

    User newUser = new User("", "", "", 0, "", 0, 0, 0);
    usersRef.child(userId).setValue(newUser);

    Steps steps = new Steps(0);
    stepsRef.child(userId).setValue(steps);

    Calories calories = new Calories(0, 0, 0, 0);
    caloriesRef.child(userId).setValue(calories);
}
 
Example 22
private void createUserOnFirebaseAuthentication(final String email,
                                                    final String password,
                                                    final OnUserCreatedOnFirebaseCallback onUserCreatedOnFirebaseCallback) {
        mAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(ChatSignUpActivity.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
//                        Toast.makeText(ChatSignUpActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
                        progressBar.setVisibility(View.GONE);
                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {
                            onUserCreatedOnFirebaseCallback.onUserCreatedError(task.getException());
                        } else {
                            // user created with success
                            FirebaseUser firebaseUser = mAuth.getCurrentUser(); // retrieve the created user
                            onUserCreatedOnFirebaseCallback.onUserCreatedSuccess(firebaseUser.getUid());
                        }
                    }
                });
    }
 
Example 23
Source Project: firebase-chat   Source File: AddUserInteractor.java    License: MIT License 6 votes vote down vote up
@Override
public void addUserToDatabase(final Context context, FirebaseUser firebaseUser) {
    DatabaseReference database = FirebaseDatabase.getInstance().getReference();
    User user = new User(firebaseUser.getUid(),
            firebaseUser.getEmail(),
            new SharedPrefUtil(context).getString(Constants.ARG_FIREBASE_TOKEN));
    database.child(Constants.ARG_USERS)
            .child(firebaseUser.getUid())
            .setValue(user)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        mOnUserDatabaseListener.onSuccess(context.getString(R.string.user_successfully_added));
                    } else {
                        mOnUserDatabaseListener.onFailure(context.getString(R.string.user_unable_to_add));
                    }
                }
            });
}
 
Example 24
Source Project: kute   Source File: SplashActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initFirebase(){
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            // ...
        }
    };


}
 
Example 25
Source Project: quickstart-android   Source File: AnonymousAuthActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void updateUI(FirebaseUser user) {
    hideProgressBar();

    TextView idView = findViewById(R.id.anonymousStatusId);
    TextView emailView = findViewById(R.id.anonymousStatusEmail);
    boolean isSignedIn = (user != null);

    // Status text
    if (isSignedIn) {
        idView.setText(getString(R.string.id_fmt, user.getUid()));
        emailView.setText(getString(R.string.email_fmt, user.getEmail()));
    } else {
        idView.setText(R.string.signed_out);
        emailView.setText(null);
    }

    // Button visibility
    findViewById(R.id.buttonAnonymousSignIn).setEnabled(!isSignedIn);
    findViewById(R.id.buttonAnonymousSignOut).setEnabled(isSignedIn);
    findViewById(R.id.buttonLinkAccount).setEnabled(isSignedIn);
}
 
Example 26
Source Project: gdx-fireapp   Source File: UserTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void sendEmailVerification_fail() {
    // Given
    User user = new User();
    FirebaseUser firebaseUser = Mockito.mock(FirebaseUser.class);
    BiConsumer consumer = Mockito.mock(BiConsumer.class);
    Mockito.when(firebaseAuth.getCurrentUser()).thenReturn(firebaseUser);
    Mockito.when(task.isSuccessful()).thenReturn(false);
    Mockito.when(firebaseUser.sendEmailVerification()).thenReturn(task);

    // When
    user.sendEmailVerification().fail(consumer);

    // Then
    Mockito.verify(firebaseUser, VerificationModeFactory.times(1)).sendEmailVerification();
    Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(String.class), Mockito.nullable(Exception.class));
}
 
Example 27
Source Project: eternity   Source File: ChatPresenter.java    License: Apache License 2.0 5 votes vote down vote up
private void initCurrentUser(View view) {
  FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
  if (user == null) {
    view.startSignInActivity();
    return;
  }

  view.setAvatar(user.getPhotoUrl());
}
 
Example 28
Source Project: snippets-android   Source File: ReferralActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // ...

    FirebaseDynamicLinks.getInstance()
            .getDynamicLink(getIntent())
            .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
                @Override
                public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                    // Get deep link from result (may be null if no link is found)
                    Uri deepLink = null;
                    if (pendingDynamicLinkData != null) {
                        deepLink = pendingDynamicLinkData.getLink();
                    }
                    //
                    // If the user isn't signed in and the pending Dynamic Link is
                    // an invitation, sign in the user anonymously, and record the
                    // referrer's UID.
                    //
                    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                    if (user == null
                            && deepLink != null
                            && deepLink.getBooleanQueryParameter("invitedby", false)) {
                        String referrerUid = deepLink.getQueryParameter("invitedby");
                        createAnonymousAccountWithReferrerInfo(referrerUid);
                    }
                }
            });
}
 
Example 29
Source Project: YTPlayer   Source File: SettingsFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void firebaseAuthWithGoogle(final GoogleSignInAccount acct) {
    Log.d("firebaseAuth", "firebaseAuthWithGoogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(activity, task -> {
                if (task.isSuccessful()) {
                    FirebaseUser user = mAuth.getCurrentUser();
                    account.setSummary(user.getUid());

                } else {
                    Log.e("GoogleSignFailed",task.getException().getMessage()+"");
                    Toast.makeText(activity,"Sign in failed!",Toast.LENGTH_SHORT).show();
                }
            });
}
 
Example 30
private void handleNewPostCreatedAction(RemoteMessage remoteMessage) {
    String postAuthorId = remoteMessage.getData().get(AUTHOR_ID_KEY);
    FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();

    //Send notification for each users except author of post.
    if (firebaseUser != null && !firebaseUser.getUid().equals(postAuthorId)) {
        PostManager.getInstance(this.getApplicationContext()).incrementNewPostsCounter();
    }
}