private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId()); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mFirebaseAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // 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()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(SignInActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } else { startActivity(new Intent(SignInActivity.this, MainActivity.class)); finish(); } } }); }
private void LoginVersuch() { // // https://firebase.google.com/docs/auth/android/password-auth email = et_mail.getText().toString(); pwd = et_password.getText().toString(); mAuth.signInWithEmailAndPassword(email, pwd) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { Log.w("AndroidLoginVersuch", "signInWithEmail:failed", task.getException()); Toast.makeText(LoginActivity.this, "Sorry, der Login ist leider fehlgeschlagen.", Toast.LENGTH_SHORT).show(); } else { Log.d("AndroidLoginVersuch", "signInWithEmail:onComplete:"); startActivity(new Intent(LoginActivity.this, MainActivity.class)); } } }); }
private void onWriteClicked() { String random = UUID.randomUUID().toString(); Map<String, Object> map = new HashMap<>(); map.put("text", random); mFirestore.collection(DEFAULT_COLLECTION) .document() .set(map) .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { Log.d(TAG, "write:onComplete"); if (!task.isSuccessful()) { Log.w(TAG, "write:onComplete:failed", task.getException()); } } }); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); FirebaseApp.initializeApp(this); FirebaseAuth.getInstance().addAuthStateListener(this); FirebaseAuth.getInstance().signInAnonymously() .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful()); // 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()) { Log.w(TAG, "signInAnonymously", task.getException()); Toast.makeText(TestActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
private void updateProfile() { // [START update_profile] FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName("Jane Q. User") .setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg")) .build(); user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "User profile updated."); } } }); // [END update_profile] }
/** * Authenticate Google user with Firebase * @param acct Google account */ private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mAuth.signInWithCredential(credential) .addOnCompleteListener(mContext, 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"); onSuccess(); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); onFailed(); } } }); }
@Override public void handleRatingUpdateAction(int fontIndex, UrduFont font) { if (font == null) { handleError(R.string.error_message_unknown_font); } else { tracker.submitFontRating(font.getName(), font.getLastRatingValue()); databaseReference.child(String.valueOf(fontIndex)) .setValue(font) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { view.showToast(R.string.thank_you); } else { handleError(R.string.error_unable_to_update_rating); } } }); } }
/** * Method createAccount * * Allows an unregistered user to create himself an account. * * @param email mail address used for his account * @param password password to access his account */ private void createAccount(String email, String password) { mFirebaseAuth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful()); // 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()) { Log.w(TAG, "signInWithEmail", task.getException()); Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } else { startActivity(new Intent(LoginActivity.this, HomeActivity.class)); finish(); } } }); }
/** * @param emit * @param <R> * @return */ @NonNull @CheckReturnValue public static <R> OnCompleteListener<R> listener(@NonNull final CompletableEmitter emit) { return new OnCompleteListener<R>() { @Override public void onComplete(@NonNull final Task<R> task) { if (!emit.isDisposed()) { if (task.isSuccessful()) { emit.onComplete(); } else { Exception e = task.getException(); emit.onError(e != null ? e : new RuntimeException()); } } } }; }
public void shotenLongLink() { // [START shorten_long_link] Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink() .setLongLink(Uri.parse("https://abc123.app.goo.gl/?link=https://example.com/&apn=com.example.android&ibn=com.example.ios")) .buildShortDynamicLink() .addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() { @Override public void onComplete(@NonNull Task<ShortDynamicLink> task) { if (task.isSuccessful()) { // Short link created Uri shortLink = task.getResult().getShortLink(); Uri flowchartLink = task.getResult().getPreviewLink(); } else { // Error // ... } } }); // [END shorten_long_link] }
public void removePost(final Post post, final OnTaskCompleteListener onTaskCompleteListener) { final DatabaseHelper databaseHelper = ApplicationHelper.getDatabaseHelper(); Task<Void> removeImageTask = removeImage(post.getImageTitle()); removeImageTask.addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { databaseHelper.removePost(post).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { onTaskCompleteListener.onTaskComplete(task.isSuccessful()); databaseHelper.updateProfileLikeCountAfterRemovingPost(post); LogUtil.logDebug(TAG, "removePost(), is success: " + task.isSuccessful()); } }); LogUtil.logDebug(TAG, "removeImage(): success"); } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception exception) { LogUtil.logError(TAG, "removeImage()", exception); onTaskCompleteListener.onTaskComplete(false); } }); }
private void getSignRequest() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) { Log.i(TAG, "getSignRequest permission is granted"); Task<SignRequestParams> getSignRequestTask = asyncGetSignRequest(); getSignRequestTask.addOnCompleteListener(new OnCompleteListener<SignRequestParams>() { @Override public void onComplete(@NonNull Task<SignRequestParams> task) { SignRequestParams signRequest = task.getResult(); if (signRequest == null) { Log.i(TAG, "signRequest is null"); return; } sendSignRequestToClient(signRequest); } }); } else { Log.i(TAG, "getSignRequest permission is requested"); ActivityCompat.requestPermissions( this, new String[]{Manifest.permission.GET_ACCOUNTS}, GET_ACCOUNTS_PERMISSIONS_REQUEST_SIGN); } }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); fireBaseAuth.signInWithCredential(credential) .addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // 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()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(getApplicationContext(), "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
public void handleAccessToken(AccessToken token) { Utils.d("FB:Handle:AccessToken: " + token.getToken()); // showProgressDialog(); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Utils.d("FB:signInWithCredential:onComplete:" + task.isSuccessful()); // 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()) { Utils.w("FB:signInWithCredential" + task.getException().toString()); } // hideProgressDialog(); } }); }
/** * Method firebaseAuthWithGoogle * * Authenticates in Firebase through a Google Account. */ private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mFirebaseAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // 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()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } else { startActivity(new Intent(LoginActivity.this, HomeActivity.class)); finish(); } } }); }
private void handleTwitterSession(TwitterSession session) { Utils.d("Twitter:HandleSession:" + session); AuthCredential credential = TwitterAuthProvider.getCredential( session.getAuthToken().token, session.getAuthToken().secret); mAuth.signInWithCredential(credential) .addOnCompleteListener(activity, 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 Utils.d("signInWithCredential:success"); } else { // If sign in fails, display a message to the user. Utils.w("signInWithCredential:failure: " + task.getException()); } // ... } }); }
protected void deletePost(Post post) { mPostReference.child(post.getKey().toString()).setValue(null).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.d(LOG_TAG, e.getLocalizedMessage()); } }).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { deleteAuthorsAndPostsCount++; if(deleteAuthorsAndPostsCount== ITERATIONS){ deleteAuthorsAndPostsCount = 0; logEvent("Delete "+ ITERATIONS +" Authors with Posts", initialTimeDeleteAuthorsAndPosts, new Date()); selectCount(); } } }); mPostReference.push(); }
private void signInWithEmail(final String email, final String password) { mAuth.signInWithEmailAndPassword(email, password) .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, "signInWithEmail:success"); FirebaseUser user = mAuth.getCurrentUser(); Toast.makeText(AccountActivity.this, "Authentication successful", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(AccountActivity.this, HomeActivity.class); startActivity(intent); finish(); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithEmail:failure. Signing Up for new account instead.", task.getException()); Toast.makeText(AccountActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
@Test public void testSingleFailure() { final String hello = "Hello, world!"; when(mockHelloTask.isSuccessful()) .thenReturn(false); when(mockHelloTask.getException()) .thenReturn(new RuntimeException(hello)); when(mockHelloTask.addOnCompleteListener(onComplete.capture())) .thenReturn(mockHelloTask); TestObserver<String> obs = TestObserver.create(); RxTask.single(mockHelloTask).subscribe(obs); verify(mockHelloTask).addOnCompleteListener(onComplete.capture()); onComplete.getValue().onComplete(mockHelloTask); obs.assertError(RuntimeException.class) .assertErrorMessage(hello) .dispose(); verify(mockHelloTask).addOnCompleteListener(any(OnCompleteListener.class)); verify(mockHelloTask).getException(); }
private void checkAccountEmailExistsInFirebase(final String email) { if(!validateEmail()) return; mProgressDialog.setTitle("Resetting Password"); mProgressDialog.setMessage("Please wait while we send password reset email."); mProgressDialog.setCanceledOnTouchOutside(false); mProgressDialog.show(); mFirebaseAuth = FirebaseAuth.getInstance(); mFirebaseAuth.fetchProvidersForEmail(email).addOnCompleteListener(new OnCompleteListener<ProviderQueryResult>() { @Override public void onComplete(@NonNull Task<ProviderQueryResult> task) { //Log.d(TAG, "checking email exists."); if(task.getResult().getProviders() != null){ resetPassword(task.getResult().getProviders(), email); } } }); }
public void createShortLink() { // [START create_short_link] Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse("https://example.com/")) .setDynamicLinkDomain("abc123.app.goo.gl") // Set parameters // ... .buildShortDynamicLink() .addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() { @Override public void onComplete(@NonNull Task<ShortDynamicLink> task) { if (task.isSuccessful()) { // Short link created Uri shortLink = task.getResult().getShortLink(); Uri flowchartLink = task.getResult().getPreviewLink(); } else { // Error // ... } } }); // [END create_short_link] }
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { //Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mFirebaseAuth.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"); Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class); mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); mProgressDialog.dismiss(); startActivity(mainIntent); finish(); } else { // If sign in fails, display a message to the user. //Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(RegisterActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
protected void updateAuthorAndYourPosts(final Author author) { mAuthorReference.child(author.getKey()).setValue(author).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.d(LOG_TAG, e.getLocalizedMessage()); } }).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { updateAuthorCount++; if(updateAuthorCount== ITERATIONS){ logEvent("Update "+ ITERATIONS +" Authors", initialTimeUpdateAuthor, new Date()); selectCount(); } } }); mAuthorReference.push(); }
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); 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(); printLog(TAG, "current user :" + user.getDisplayName()); updateUser(user); updateUi(); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(RegisterActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // ... } }); }
private void updateRegisterResponseToServer(RegisterResponseData registerResponseData) { /* assume this operation can only happen within short time after getRegisterRequest, which has already checked permission */ Task<String> updateRegisterResponseToServerTask = asyncUpdateRegisterResponseToServer(registerResponseData); updateRegisterResponseToServerTask.addOnCompleteListener(new OnCompleteListener<String>() { @Override public void onComplete(@NonNull Task<String> task) { String securityKeyToken = task.getResult(); if (securityKeyToken == null) { Toast.makeText( U2FDemoActivity.this, "security key registration failed", Toast.LENGTH_SHORT) .show(); return; } updateAndDisplayRegisteredKeys(); Log.i(TAG, "Update register response to server with securityKeyToken: " + securityKeyToken); } }); }
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // 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()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(SignInActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
private void getMultipleDocs() { // [START get_multiple] db.collection("cities") .whereEqualTo("capital", true) .get() .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { @Override public void onComplete(@NonNull Task<QuerySnapshot> task) { if (task.isSuccessful()) { for (DocumentSnapshot document : task.getResult()) { Log.d(TAG, document.getId() + " => " + document.getData()); } } else { Log.d(TAG, "Error getting documents: ", task.getException()); } } }); // [END get_multiple] }
@Override public Completable deleteProfile(final String uid) { return Completable.create( new CompletableOnSubscribe() { @Override public void subscribe(final CompletableEmitter e) throws Exception { final DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference(); rootRef.child(USER_PROFILES) .child(uid) .setValue(null) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { e.onComplete(); } else { e.onError(task.getException()); } } }); } }); }
private void updateAndDisplayRegisteredKeys() { mProgressBar.setVisibility(View.VISIBLE); if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) { Log.i(TAG, "updateAndDisplayRegisteredKeys permission is granted"); Task<List<Map<String, String>>> refreshSecurityKeyTask = asyncRefreshSecurityKey(); refreshSecurityKeyTask.addOnCompleteListener( new OnCompleteListener<List<Map<String, String>>>() { @Override public void onComplete(@NonNull Task<List<Map<String, String>>> task) { List<Map<String, String>> tokens = task.getResult(); securityTokens = tokens; mAdapter.clearSecurityTokens(); mAdapter.addSecurityToken(securityTokens); displayRegisteredKeys(); } }); } else { Log.i(TAG, "updateAndDisplayRegisteredKeys permission is requested"); ActivityCompat.requestPermissions( this, new String[]{Manifest.permission.GET_ACCOUNTS}, GET_ACCOUNTS_PERMISSIONS_ALL_TOKENS); } }
private void fetchFirebaseRemoteConfig() { long cacheExpiration = 36008*12; // 12 hour in seconds. mFirebaseRemoteConfig.fetch(cacheExpiration) .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { // After config data is successfully fetched, it must be activated before newly fetched // values are returned. mFirebaseRemoteConfig.activateFetched(); } /*else { Toast.makeText(MainActivity.this, "Fetch Failed", Toast.LENGTH_SHORT).show(); }*/ // comment it out to test getRemoteConfigs(); } }); }
private void createAccount() { progressBar.setVisibility(View.VISIBLE); mAuth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful()); isRegistrationClicked = true; // 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()) { Toast.makeText(newUser.this, R.string.auth_failed, Toast.LENGTH_SHORT).show(); setViews(true); isRegistrationClicked = false; progressBar.setVisibility(View.GONE); } // ... } }); }
@Override public Completable deleteUser() { return Completable.create(new CompletableOnSubscribe() { @Override public void subscribe(final CompletableEmitter e) throws Exception { if (auth == null) { auth = FirebaseAuth.getInstance(); } final FirebaseUser user = auth.getCurrentUser(); user.delete().addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { e.onComplete(); } else { e.onError(task.getException()); } } }); } }); }
/** * Delete a user from the database */ public void deleteUserFromDatabase() { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user != null) { String userId = user.getUid(); getDatabaseManager().deleteUserRecords(getActivity(), userId); user.delete().addOnCompleteListener(new OnCompleteListener<Void>() { /** * Delete the user task completed * @param task - the completed task */ @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { mUser = null; } } }); resetDatabaseManager(); } }
private void sendEmailVerification() { // Send verification email // [START send_email_verification] final FirebaseUser user = mAuth.getCurrentUser(); user.sendEmailVerification() .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { // [START_EXCLUDE] // Re-enable button if (task.isSuccessful()) { Toast.makeText(SignupActivity.this, "Verification email sent to " + user.getEmail(), Toast.LENGTH_SHORT).show(); } else { Log.e(TAG, "sendEmailVerification", task.getException()); Toast.makeText(SignupActivity.this, "Failed to send verification email.", Toast.LENGTH_SHORT).show(); } // [END_EXCLUDE] } }); // [END send_email_verification] }
private void sendEmailVerification() { firebaseAuth.getCurrentUser().sendEmailVerification() .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Toast.makeText(RegisterActivity.this, "Verification email sent to " + firebaseAuth.getCurrentUser().getEmail(), Toast.LENGTH_SHORT).show(); Intent registerIntent = new Intent(RegisterActivity.this, LoginActivity.class); startActivity(registerIntent); } else { Toast.makeText(RegisterActivity.this, "Failed to send verification email.", Toast.LENGTH_SHORT).show(); } } }); }
@Override public void createMessage( final String uid, final Message message, final DatabaseCallback<Message> dbCallback) { dbReference .child(uid) .child(MESSAGES) .push() .setValue(message) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { dbCallback.onSuccess(message); } else { dbCallback.onFailure(task.getException()); } } }); }
private void link() { if (phoneNumberCheck() == true) { mAuth.getCurrentUser().linkWithCredential(credent) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { Log.d(TAG, "linkWithCredential:success"); Toast.makeText(ChangePhoneNumberActivity.this, "변경되었습니다", Toast.LENGTH_SHORT).show(); IntentBack(); } else { Log.w(TAG, "linkWithCredential:failure", task.getException()); Toast.makeText(ChangePhoneNumberActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // ... } }); } else { Toast.makeText(ChangePhoneNumberActivity.this, "이미 등록되어있는 번호입니다.", Toast.LENGTH_SHORT).show(); } }