當前位置: 首頁>>代碼示例>>Java>>正文


Java Task類代碼示例

本文整理匯總了Java中com.google.android.gms.tasks.Task的典型用法代碼示例。如果您正苦於以下問題:Java Task類的具體用法?Java Task怎麽用?Java Task使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Task類屬於com.google.android.gms.tasks包,在下文中一共展示了Task類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendEmailVerification

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
public void sendEmailVerification() {
    // [START send_email_verification]
    FirebaseAuth auth = FirebaseAuth.getInstance();
    FirebaseUser user = auth.getCurrentUser();

    user.sendEmailVerification()
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "Email sent.");
                    }
                }
            });
    // [END send_email_verification]
}
 
開發者ID:firebase,項目名稱:snippets-android,代碼行數:17,代碼來源:MainActivity.java

示例2: performFirebaseRegistration

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
@Override
public void performFirebaseRegistration(Activity activity, final String email, String password) {
    FirebaseAuth.getInstance()
            .createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.e(TAG, "performFirebaseRegistration: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()) {
                        mOnRegistrationListener.onFailure(task.getException().getMessage());
                    } else {
                        // Add the user to users table.
                        /*DatabaseReference database= FirebaseDatabase.getInstance().getReference();
                        User user = new User(task.getResult().getUser().getUid(), email);
                        database.child("users").push().setValue(user);*/

                        mOnRegistrationListener.onSuccess(task.getResult().getUser());
                    }
                }
            });
}
 
開發者ID:mustafaozhan,項目名稱:Howl,代碼行數:26,代碼來源:RegisterInteractor.java

示例3: sendPasswordResetMail

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
@Override
public Promise<Void, BError, Void> sendPasswordResetMail(String email){

    final Deferred<Void, BError, Void> deferred = new DeferredObject<>();

    OnCompleteListener<Void> resultHandler = new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                if(DEBUG) Timber.v("Email sent");
                deferred.resolve(null);
            } else {
                deferred.reject(getFirebaseError(DatabaseError.fromException(task.getException())));

            }
        }
    };

    FirebaseAuth.getInstance().sendPasswordResetEmail(email).addOnCompleteListener(resultHandler);
    
    return deferred.promise();
}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:23,代碼來源:BChatcatNetworkAdapter.java

示例4: getAllUsers

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
private void getAllUsers() {
    // [START get_all_users]
    db.collection("users")
            .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.w(TAG, "Error getting documents.", task.getException());
                    }
                }
            });
    // [END get_all_users]
}
 
開發者ID:firebase,項目名稱:snippets-android,代碼行數:19,代碼來源:DocSnippets.java

示例5: reauthenticate

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
private void reauthenticate() {
    // [START reauthenticate]
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    // Get auth credentials from the user for re-authentication. The example below shows
    // email and password credentials but there are multiple possible providers,
    // such as GoogleAuthProvider or FacebookAuthProvider.
    AuthCredential credential = EmailAuthProvider
            .getCredential("[email protected]", "password1234");

    // Prompt the user to re-provide their sign-in credentials
    user.reauthenticate(credential)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    Log.d(TAG, "User re-authenticated.");
                }
            });
    // [END reauthenticate]
}
 
開發者ID:firebase,項目名稱:snippets-android,代碼行數:21,代碼來源:MainActivity.java

示例6: onComplete

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
@Override
public void onComplete(@NonNull Task<Void> task) {
    if (isDisposed()) return;
    if (!task.isSuccessful()) {
        Exception exception = task.getException();
        if (terminated) {
            RxJavaPlugins.onError(exception);
        } else {
            try {
                terminated = true;
                observer.onError(exception);
            } catch (Throwable t) {
                Exceptions.throwIfFatal(t);
                RxJavaPlugins.onError(new CompositeException(task.getException(), t));
            }
        }
    }
}
 
開發者ID:niqo01,項目名稱:RxTask,代碼行數:19,代碼來源:ObservableTaskCallback.java

示例7: firebaseAuthWithGoogle

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    LogUtil.logDebug(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    showProgress();

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    LogUtil.logDebug(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()) {
                        handleAuthError(task);
                    }
                }
            });
}
 
開發者ID:rozdoum,項目名稱:social-app-android,代碼行數:21,代碼來源:LoginActivity.java

示例8: signIn

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
@Override
public final void signIn(final String email, final String password, final Callback callback) {
    signInCallback = callback;

    // TODO: 23-Feb-17 validate email, pass;

    firebaseAuthManager.signInWithEmailAndPassword(email, password, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            final Exception exception = task.getException();
            printStackTrace(exception);
            if (signInCallback != null) {
                signInCallback.onComplete(task.isSuccessful(), exception != null ? exception.getMessage() : "");
            }
        }
    });
}
 
開發者ID:thinkmobiles,項目名稱:Android-MVP-vs-MVVM-Samples,代碼行數:18,代碼來源:AuthModuleImpl.java

示例9: subscribe

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
@Override
public void subscribe(final CompletableEmitter emitter) throws Exception {
    final OnCompleteListener<Void> listener = new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {

            if (!emitter.isDisposed()) {
                if (!task.isSuccessful()) {
                    emitter.onError(task.getException());
                } else {
                    emitter.onComplete();
                }
            }

        }
    };

    reference.set(value).addOnCompleteListener(listener);

}
 
開發者ID:btrautmann,項目名稱:RxFirestore,代碼行數:21,代碼來源:SetOnSubscribe.java

示例10: LoginAnonymously

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
private void LoginAnonymously() {
    mAuth.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(MainActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // ...
                }
            });
}
 
開發者ID:othreecodes,項目名稱:WaJeun,代碼行數:21,代碼來源:MainActivity.java

示例11: firebaseAuthWithGoogle

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
/**
 * 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();
                    }
                }
            });
}
 
開發者ID:CMPUT301F17T13,項目名稱:cat-is-a-dog,代碼行數:25,代碼來源:GoogleAuthenticator.java

示例12: onCreate

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
@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();
                    }
                }
            });
}
 
開發者ID:crysxd,項目名稱:shared-firebase-preferences,代碼行數:27,代碼來源:TestActivity.java

示例13: firebaseAuthWithGoogle

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
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();
                    }
                }
            });
}
 
開發者ID:firebase,項目名稱:friendlychat-android,代碼行數:24,代碼來源:SignInActivity.java

示例14: handleSignInResult

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
private void handleSignInResult(Task<GoogleSignInAccount> completedTask){
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);

        // Signed in successfully, show authenticated UI.
        updateUI(account);

        googleSignInAccount = account;
        mAuthorizedAccount = account.getAccount();

        GetListOfBlogTask task = new GetListOfBlogTask(mAuthorizedAccount);
        task.execute();
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        // Please refer to the GoogleSignInStatusCodes class reference for more information.
        Tools.loge("signInResult:failed code=" + e.getStatusCode());
        updateUI(null);
    }
}
 
開發者ID:thenewpotato,項目名稱:Blogg,代碼行數:20,代碼來源:MainActivity.java

示例15: onActivityResult

import com.google.android.gms.tasks.Task; //導入依賴的package包/類
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (fullScreenChatWindow != null) fullScreenChatWindow.onActivityResult(requestCode, resultCode, data);
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        // The Task returned from this call is always completed, no need to attach
        // a listener.
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        handleSignInResult(task);
    }
    else {
        Log.w("Chat", "Received unknown code " + requestCode);
    }
}
 
開發者ID:coe-google-apps-support,項目名稱:jazz-android,代碼行數:17,代碼來源:MainActivity.java


注:本文中的com.google.android.gms.tasks.Task類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。