本文整理汇总了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]
}
示例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());
}
}
});
}
示例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();
}
示例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]
}
示例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]
}
示例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));
}
}
}
}
示例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);
}
}
});
}
示例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() : "");
}
}
});
}
示例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);
}
示例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();
}
// ...
}
});
}
示例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();
}
}
});
}
示例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();
}
}
});
}
示例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();
}
}
});
}
示例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);
}
}
示例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);
}
}