当前位置: 首页>>代码示例>>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;未经允许,请勿转载。