com.google.android.gms.tasks.OnCompleteListener Java Examples
The following examples show how to use
com.google.android.gms.tasks.OnCompleteListener.
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: ScheduleFragment.java From KUAS-AP-Material with MIT License | 7 votes |
private void getScheduleData() { mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() .setDeveloperModeEnabled(BuildConfig.DEBUG).build(); mFirebaseRemoteConfig.setConfigSettings(configSettings); mFirebaseRemoteConfig.fetch(60).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful() && !activity.isFinishing()) { mFirebaseRemoteConfig.activateFetched(); try { mScheduleData = mFirebaseRemoteConfig.getString("schedule_data"); setUpViews(); } catch (Exception e) { // ignore } } } }); }
Example #2
Source File: forgotPassword.java From NITKart with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forgot_password); email_input = (EditText)findViewById(R.id.forgot_password_email_edittext); submit = (Button)findViewById(R.id.forgot_password_email_submit); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FirebaseAuth.getInstance().sendPasswordResetEmail(email_input.getText().toString()) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d("PasswordResetMail", "Email sent."); Toast.makeText(getApplicationContext(), R.string.reset_password_toast, Toast.LENGTH_LONG).show(); finish(); } } }); } }); }
Example #3
Source File: WearableUtil.java From APDE with GNU General Public License v2.0 | 6 votes |
public static void sendApkToWatch(Context context, File apkFile, final ResultCallback callback) { Uri apkUri = FileProvider.getUriForFile(context, "com.calsignlabs.apde.fileprovider", apkFile); Asset asset = Asset.createFromUri(apkUri); PutDataMapRequest dataMap = PutDataMapRequest.create("/apk"); dataMap.getDataMap().putAsset("apk", asset); dataMap.getDataMap().putLong("timestamp", System.currentTimeMillis()); PutDataRequest request = dataMap.asPutDataRequest(); request.setUrgent(); Task<DataItem> putTask = Wearable.getDataClient(context).putDataItem(request); putTask.addOnCompleteListener(new OnCompleteListener<DataItem>() { @Override public void onComplete(@NonNull Task<DataItem> task) { if (task.isSuccessful()) { callback.success(); } else { callback.failure(); } } }); }
Example #4
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 6 votes |
public void createShortLink() { // [START create_short_link] Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse("https://www.example.com/")) .setDomainUriPrefix("https://example.page.link") // 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] }
Example #5
Source File: SignInActivity.java From codelab-friendlychat-android with Apache License 2.0 | 6 votes |
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(SignInActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } else { startActivity(new Intent(SignInActivity.this, MainActivity.class)); finish(); } } }); }
Example #6
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 6 votes |
public 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] }
Example #7
Source File: MainWearActivity.java From wear-os-samples with Apache License 2.0 | 6 votes |
private void checkIfPhoneHasApp() { Log.d(TAG, "checkIfPhoneHasApp()"); Task<CapabilityInfo> capabilityInfoTask = Wearable.getCapabilityClient(this) .getCapability(CAPABILITY_PHONE_APP, CapabilityClient.FILTER_ALL); capabilityInfoTask.addOnCompleteListener(new OnCompleteListener<CapabilityInfo>() { @Override public void onComplete(Task<CapabilityInfo> task) { if (task.isSuccessful()) { Log.d(TAG, "Capability request succeeded."); CapabilityInfo capabilityInfo = task.getResult(); mAndroidPhoneNodeWithApp = pickBestNodeId(capabilityInfo.getNodes()); } else { Log.d(TAG, "Capability request failed to return any results."); } verifyNodeAndUpdateUI(); } }); }
Example #8
Source File: AuthUtils.java From android-docs-samples with Apache License 2.0 | 6 votes |
/** * function to signin to Firebase Anonymously * @param activity : Instance of the Activity */ public static void signInAnonymously(final Activity activity) { firebaseAuth = FirebaseAuth.getInstance(); firebaseAuth.signInAnonymously() .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 Toast.makeText(activity, "Sign In was successful", Toast.LENGTH_SHORT).show(); } else { // If sign in fails, display a message to the user. Toast.makeText(activity, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
Example #9
Source File: AuthTest.java From gdx-fireapp with Apache License 2.0 | 6 votes |
@Test public void signInAnonymously_fail() { // Given Auth auth = new Auth(); BiConsumer biConsumer = Mockito.mock(BiConsumer.class); Mockito.when(task.isSuccessful()).thenReturn(false); Mockito.when(task.getException()).thenReturn(new Exception()); Mockito.doReturn(task).when(firebaseAuth).signInAnonymously(); // When auth.signInAnonymously() .fail(biConsumer); // Then PowerMockito.verifyStatic(FirebaseAuth.class, VerificationModeFactory.times(1)); FirebaseAuth.getInstance(); Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).signInAnonymously(); Mockito.verify(task, VerificationModeFactory.times(1)).addOnCompleteListener(Mockito.any(OnCompleteListener.class)); Mockito.verify(biConsumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(String.class), Mockito.any(Exception.class)); }
Example #10
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 6 votes |
public void updatePassword() { // [START update_password] FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); String newPassword = "SOME-SECURE-PASSWORD"; user.updatePassword(newPassword) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "User password updated."); } } }); // [END update_password] }
Example #11
Source File: CompanionNotifyActivity.java From PixelWatchFace with GNU General Public License v3.0 | 6 votes |
private void checkIfPhoneHasApp() { Log.d(TAG, "checkIfPhoneHasApp()"); Task<CapabilityInfo> capabilityInfoTask = Wearable.getCapabilityClient(this) .getCapability(CAPABILITY_PHONE_APP, CapabilityClient.FILTER_ALL); capabilityInfoTask.addOnCompleteListener(new OnCompleteListener<CapabilityInfo>() { @Override public void onComplete(Task<CapabilityInfo> task) { if (task.isSuccessful()) { Log.d(TAG, "Capability request succeeded."); CapabilityInfo capabilityInfo = task.getResult(); mAndroidPhoneNodeWithApp = pickBestNodeId(capabilityInfo.getNodes()); } else { Log.d(TAG, "Capability request failed to return any results."); } verifyNodeAndUpdateUI(); } }); }
Example #12
Source File: MainActivity.java From location-samples with Apache License 2.0 | 6 votes |
/** * Removes location updates from the FusedLocationApi. */ private void stopLocationUpdates() { if (!mRequestingLocationUpdates) { Log.d(TAG, "stopLocationUpdates: updates never requested, no-op."); return; } // It is a good practice to remove location requests when the activity is in a paused or // stopped state. Doing so helps battery performance and is especially // recommended in applications that request frequent location updates. mFusedLocationClient.removeLocationUpdates(mLocationCallback) .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { mRequestingLocationUpdates = false; setButtonsEnabledState(); } }); }
Example #13
Source File: MainActivity.java From stitch-examples with Apache License 2.0 | 6 votes |
private void clearChecked() { final Document query = new Document(); query.put("owner_id", _client.getAuth().getUser().getId()); query.put("checked", true); _remoteCollection.sync().deleteMany(query).addOnCompleteListener(new OnCompleteListener<Document>() { @Override public void onComplete(@NonNull final Task<Document> task) { if (task.isSuccessful()) { refreshList(); } else { Log.e(TAG, "Error clearing checked items", task.getException()); } } }); }
Example #14
Source File: AboutActivity.java From cannonball-android with Apache License 2.0 | 6 votes |
private void setUpSignOut() { final TextView bt = (TextView) findViewById(R.id.deactivate_accounts); final Context ctx = this; bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AuthUI.getInstance() .signOut(ctx) .addOnCompleteListener(new OnCompleteListener<Void>() { public void onComplete(Task<Void> Task) { mFirebaseAnalytics.logEvent("logout", null); Toast.makeText(getApplicationContext(), "Signed out", Toast.LENGTH_SHORT).show(); startActivity(new Intent(ctx, LoginActivity.class)); } }); } }); }
Example #15
Source File: SignupActivity.java From wmn-safety with MIT License | 6 votes |
private void signUp(final String email, final String password, final String name, final String number) { mHelpers.showProgressDialog(getString(R.string.creating_account)); mFirebaseAuth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { mHelpers.hideProgressDialog(); if (task.isSuccessful()) { Log.v(TAG, "New User Crated successfully"); String userID = mFirebaseAuth.getCurrentUser().getUid(); addNewUser(email, name, number, userID); } else { Log.w(TAG, task.getException().toString()); mHelpers.showAlertDialog(getString(R.string.error_message), task.getException().getMessage()).show(); } } }); }
Example #16
Source File: SignupActivity.java From wmn-safety with MIT License | 6 votes |
private void addNewUser(String email, String name, String number, String userID) { UserData user = new UserData(name, email, number); DatabaseReference mDatabaseReference = mFirebaseDatabase.getReference(); mDatabaseReference.child("users").child(userID).setValue(user) .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.v(TAG, "New User Data stored successfully"); Intent intent = new Intent(SignupActivity.this, SigninActivity.class); startActivity(intent); } else { mHelpers.showAlertDialog(getString(R.string.error_message), task.getException().getMessage()).show(); Log.w(TAG, task.getException().toString()); } } }); }
Example #17
Source File: SignInActivity.java From Duolingo-Clone with MIT License | 6 votes |
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { 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()) { //take me to main page Toast.makeText(context, "itworked", Toast.LENGTH_SHORT).show(); ActivityNavigation.getInstance(SignInActivity.this).takeToRandomTask(); } else { Toast.makeText(context, getString(R.string.auth_failed), Toast.LENGTH_SHORT).show(); } } }); }
Example #18
Source File: FirestackAuth.java From react-native-firestack with MIT License | 6 votes |
@ReactMethod public void signInWithCustomToken(final String customToken, final Callback callback) { mAuth = FirebaseAuth.getInstance(); mAuth.signInWithCustomToken(customToken) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCustomToken:onComplete:" + task.isSuccessful()); if (task.isSuccessful()) { FirestackAuthModule.this.user = task.getResult().getUser(); userCallback(FirestackAuthModule.this.user, callback); } else { // userErrorCallback(task, callback); } } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception ex) { userExceptionCallback(ex, callback); } }); }
Example #19
Source File: SigninActivity.java From wmn-safety with MIT License | 6 votes |
private void loginWithFirebaseEmailPassword(String email, String password) { mHelpers.showProgressDialog(getString(R.string.loading_msg)); mFirebaseAuth.signInWithEmailAndPassword(email, password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { mHelpers.hideProgressDialog(); if (task.isSuccessful()) { mHelpers.showToast(getString(R.string.login_success)); onSignInSuccess(); } else { Log.w("Sign in failed", task.getException().toString()); mHelpers.showAlertDialog(getString(R.string.error_message), task.getException().getMessage()).show(); } } }); }
Example #20
Source File: FCMRegistration.java From Android-SDK with MIT License | 6 votes |
static void unregisterDeviceOnFCM(final Context context, final AsyncCallback<Integer> callback) { FirebaseMessaging.getInstance().unsubscribeFromTopic( DEFAULT_TOPIC ).addOnCompleteListener( new OnCompleteListener<Void>() { @Override public void onComplete( @NonNull Task<Void> task ) { if( task.isSuccessful() ) { Log.d( TAG, "Unsubscribed on FCM." ); if( callback != null ) callback.handleResponse( 0 ); } else { Log.e( TAG, "Failed to unsubscribe in FCM.", task.getException() ); String reason = (task.getException() != null) ? Objects.toString( task.getException().getMessage() ) : ""; if( callback != null ) callback.handleFault( new BackendlessFault( "Failed to unsubscribe on FCM. " + reason ) ); } } } ); }
Example #21
Source File: DocSnippets.java From snippets-android with Apache License 2.0 | 6 votes |
public void updateWithServerTimestamp() { // [START update_with_server_timestamp] DocumentReference docRef = db.collection("objects").document("some-id"); // Update the timestamp field with the value from the server Map<String,Object> updates = new HashMap<>(); updates.put("timestamp", FieldValue.serverTimestamp()); docRef.update(updates).addOnCompleteListener(new OnCompleteListener<Void>() { // [START_EXCLUDE] @Override public void onComplete(@NonNull Task<Void> task) {} // [START_EXCLUDE] }); // [END update_with_server_timestamp] }
Example #22
Source File: AuthTest.java From gdx-fireapp with Apache License 2.0 | 6 votes |
@Override public void setup() throws Exception { super.setup(); PowerMockito.mockStatic(FirebaseAuth.class); firebaseAuth = PowerMockito.mock(FirebaseAuth.class); Mockito.when(firebaseAuth.getCurrentUser()).thenReturn(Mockito.mock(FirebaseUser.class)); task = PowerMockito.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; } }); Mockito.when(FirebaseAuth.getInstance()).thenReturn(firebaseAuth); }
Example #23
Source File: OtpGenerator.java From GetIntoClub with GNU General Public License v3.0 | 6 votes |
private void SigninWithPhone(PhoneAuthCredential credential) { auth.signInWithCredential(credential) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { FirebaseAuth.getInstance().signOut(); startActivity(new Intent(OtpGenerator.this, DashActivity.class)); finish(); } else { Toast.makeText(OtpGenerator.this, "Incorrect OTP", Toast.LENGTH_SHORT).show(); } } }); }
Example #24
Source File: EventDetailsActivity.java From NaviBee with GNU General Public License v3.0 | 6 votes |
private void deleteEvent() { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setMessage(getString(R.string.event_delete_confirmation, eventItem.getName())); dialog.setNegativeButton(R.string.action_cancel, (dialoginterface, i) -> dialoginterface.cancel()); dialog.setPositiveButton(R.string.action_delete, (dialoginterface, i) -> db.collection("events").document(eid).delete().addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { // TODO: Task completed successfully finish(); } else { Snackbar.make(coordinatorLayout, R.string.error_failed_to_connect_to_server, Snackbar.LENGTH_SHORT).show(); } } })); dialog.show(); }
Example #25
Source File: MainActivity.java From android-basic-samples with Apache License 2.0 | 6 votes |
public void signOut() { Log.d(TAG, "signOut()"); mGoogleSignInClient.signOut().addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "signOut(): success"); } else { handleException(task.getException(), "signOut() failed!"); } onDisconnected(); } }); }
Example #26
Source File: LoginActivity.java From NaviBee with GNU General Public License v3.0 | 6 votes |
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"); checkSignIn(); } else { // If sign in fails, display a message to the user. Toast.makeText(LoginActivity.this, "Sign in fails", Toast.LENGTH_LONG).show(); } } }); }
Example #27
Source File: FireSignin.java From Learning-Resources with MIT License | 6 votes |
private void firebaseAuthWithFacebook(AccessToken accessToken) { mPrgrsbrMain.setVisibility(View.VISIBLE); LogManager.printLog(LOGTYPE_INFO, "signInWithFacebookToken: " + accessToken); AuthCredential credential = FacebookAuthProvider.getCredential(accessToken.getToken()); mFireAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { LogManager.printLog(LOGTYPE_DEBUG, "signInWithCredential:onComplete:" + task.isSuccessful()); if (!task.isSuccessful()) { mPrgrsbrMain.setVisibility(View.GONE); Log.w(LOG_TAG, "signInWithCredential", task.getException()); Snackbar.make(mCrdntrlyot, "Authentication failed.\n" + task.getException().getMessage(), Snackbar.LENGTH_LONG).show(); } else successLoginGetData(task); } }); }
Example #28
Source File: OpenScreen.java From NITKart with MIT License | 6 votes |
public void signIn(String email, String password) { mAuth.signInWithEmailAndPassword(email, password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithEmail: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:failed", task.getException()); progressBar.setVisibility(View.GONE); Toast.makeText(getApplicationContext(), R.string.auth_failed, Toast.LENGTH_SHORT).show(); setInputs(true); } // ... } }); }
Example #29
Source File: BaseActivity.java From stockita-point-of-sale with MIT License | 6 votes |
/** * This method to sign out, from both the email sign or google sign */ protected void signOut() { AuthUI.getInstance() .signOut(this) .addOnCompleteListener(this, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { // user is now sign out // Get back to the sign in page startActivity(new Intent(getBaseContext(), SignInUI.class)); finish(); } }); }
Example #30
Source File: LoginActivity.java From logregform-android with MIT License | 6 votes |
public void signUser(String email, String password){ progressDialog.setMessage("Verificating..."); progressDialog.show(); firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if(task.isSuccessful()){ progressDialog.dismiss(); Toast.makeText(LoginActivity.this,"Login Successful",Toast.LENGTH_SHORT).show(); startActivity(new Intent(LoginActivity.this,MainActivity.class)); } else{ progressDialog.dismiss(); Toast.makeText(LoginActivity.this,"Invalid email or password",Toast.LENGTH_SHORT).show(); } } }); }