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: SnapshotCoordinator.java From android-basic-samples with Apache License 2.0 | 6 votes |
@NonNull private OnCompleteListener<SnapshotsClient.DataOrConflict<Snapshot>> createOpenListener(final String filename) { return new OnCompleteListener<SnapshotsClient.DataOrConflict<Snapshot>>() { @Override public void onComplete(@NonNull Task<SnapshotsClient.DataOrConflict<Snapshot>> task) { // if open failed, set the file to closed, otherwise, keep it open. if (!task.isSuccessful()) { Exception e = task.getException(); Log.e(TAG, "Open was not a success for filename " + filename, e); setClosed(filename); } else { SnapshotsClient.DataOrConflict<Snapshot> result = task.getResult(); if (result.isConflict()) { Log.d(TAG, "Open successful: " + filename + ", but with a conflict"); } else { Log.d(TAG, "Open successful: " + filename); } } } }; }
Example #3
Source File: MainActivity.java From location-samples with Apache License 2.0 | 6 votes |
/** * Provides a simple way of getting a device's location and is well suited for * applications that do not require a fine-grained location and that do not need location * updates. Gets the best and most recent location currently available, which may be null * in rare cases when a location is not available. * <p> * Note: this method should be called after location permission has been granted. */ @SuppressWarnings("MissingPermission") private void getLastLocation() { mFusedLocationClient.getLastLocation() .addOnCompleteListener(this, new OnCompleteListener<Location>() { @Override public void onComplete(@NonNull Task<Location> task) { if (task.isSuccessful() && task.getResult() != null) { mLastLocation = task.getResult(); mLatitudeText.setText(String.format(Locale.ENGLISH, "%s: %f", mLatitudeLabel, mLastLocation.getLatitude())); mLongitudeText.setText(String.format(Locale.ENGLISH, "%s: %f", mLongitudeLabel, mLastLocation.getLongitude())); } else { Log.w(TAG, "getLastLocation:exception", task.getException()); showSnackbar(getString(R.string.no_location_detected)); } } }); }
Example #4
Source File: MainActivity.java From identity-samples with Apache License 2.0 | 6 votes |
private void googleSilentSignIn() { // Try silent sign-in with Google Sign In API Task<GoogleSignInAccount> silentSignIn = mSignInClient.silentSignIn(); if (silentSignIn.isComplete() && silentSignIn.isSuccessful()) { handleGoogleSignIn(silentSignIn); return; } showProgress(); silentSignIn.addOnCompleteListener(new OnCompleteListener<GoogleSignInAccount>() { @Override public void onComplete(@NonNull Task<GoogleSignInAccount> task) { hideProgress(); handleGoogleSignIn(task); } }); }
Example #5
Source File: FcmPushProvider.java From MixPush with Apache License 2.0 | 6 votes |
@Override public void register(Context context) { FirebaseInstanceId.getInstance().getInstanceId() .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { @Override public void onComplete(@NonNull Task<InstanceIdResult> task) { if (!task.isSuccessful()) { // Log.w(TAG, "getInstanceId failed", task.getException()); return; } // Get new Instance ID token String token = task.getResult().getToken(); // Log and toast // String msg = getString(R.string.msg_token_fmt, token); // Log.d(TAG, msg); // Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); } }); }
Example #6
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 #7
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 #8
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 #9
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 #10
Source File: BaseAuthActivity.java From MangoBloggerAndroidApp with Mozilla Public License 2.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()) { hideProgressDialog(); // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCredential:success"); // FirebaseUser user = mAuth.getCurrentUser(); startApp(); } else { hideProgressDialog(); // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(BaseAuthActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // ... } }); }
Example #11
Source File: Auth.java From gdx-fireapp with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Promise<Void> sendPasswordResetEmail(final String email) { return FuturePromise.when(new Consumer<FuturePromise<Void>>() { @Override public void accept(final FuturePromise<Void> promise) { FirebaseAuth.getInstance().sendPasswordResetEmail(email) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { promise.doComplete(null); } else { promise.doFail(task.getException()); } } }); } }); }
Example #12
Source File: CustomAuthActivity.java From quickstart-android with Apache License 2.0 | 6 votes |
private void startSignIn() { // Initiate sign in with custom token // [START sign_in_custom] mAuth.signInWithCustomToken(mCustomToken) .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, "signInWithCustomToken:success"); FirebaseUser user = mAuth.getCurrentUser(); updateUI(user); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCustomToken:failure", task.getException()); Toast.makeText(CustomAuthActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); updateUI(null); } } }); // [END sign_in_custom] }
Example #13
Source File: MainActivity.java From android-basic-samples with Apache License 2.0 | 6 votes |
void leaveRoom() { Log.d(TAG, "Leaving room."); mSecondsLeft = 0; stopKeepingScreenOn(); if (mRoomId != null) { mRealTimeMultiplayerClient.leave(mRoomConfig, mRoomId) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { mRoomId = null; mRoomConfig = null; } }); switchToScreen(R.id.screen_wait); } else { switchToMainScreen(); } }
Example #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
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); }