本文整理匯總了Java中com.google.android.gms.tasks.OnCompleteListener類的典型用法代碼示例。如果您正苦於以下問題:Java OnCompleteListener類的具體用法?Java OnCompleteListener怎麽用?Java OnCompleteListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
OnCompleteListener類屬於com.google.android.gms.tasks包,在下文中一共展示了OnCompleteListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: firebaseAuthWithGoogle
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGooogle:" + 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();
}
}
});
}
示例2: LoginVersuch
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
private void LoginVersuch() {
// // https://firebase.google.com/docs/auth/android/password-auth
email = et_mail.getText().toString();
pwd = et_password.getText().toString();
mAuth.signInWithEmailAndPassword(email, pwd)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Log.w("AndroidLoginVersuch", "signInWithEmail:failed", task.getException());
Toast.makeText(LoginActivity.this, "Sorry, der Login ist leider fehlgeschlagen.",
Toast.LENGTH_SHORT).show();
} else {
Log.d("AndroidLoginVersuch", "signInWithEmail:onComplete:");
startActivity(new Intent(LoginActivity.this, MainActivity.class));
}
}
});
}
示例3: onWriteClicked
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
private void onWriteClicked() {
String random = UUID.randomUUID().toString();
Map<String, Object> map = new HashMap<>();
map.put("text", random);
mFirestore.collection(DEFAULT_COLLECTION)
.document()
.set(map)
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.d(TAG, "write:onComplete");
if (!task.isSuccessful()) {
Log.w(TAG, "write:onComplete:failed", task.getException());
}
}
});
}
示例4: onCreate
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的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();
}
}
});
}
示例5: updateProfile
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
private 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]
}
示例6: firebaseAuthWithGoogle
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的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();
}
}
});
}
示例7: handleRatingUpdateAction
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
@Override
public void handleRatingUpdateAction(int fontIndex, UrduFont font) {
if (font == null) {
handleError(R.string.error_message_unknown_font);
} else {
tracker.submitFontRating(font.getName(), font.getLastRatingValue());
databaseReference.child(String.valueOf(fontIndex))
.setValue(font)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
view.showToast(R.string.thank_you);
} else {
handleError(R.string.error_unable_to_update_rating);
}
}
});
}
}
示例8: createAccount
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
/**
* Method createAccount
*
* Allows an unregistered user to create himself an account.
*
* @param email mail address used for his account
* @param password password to access his account
*/
private void createAccount(String email, String password)
{
mFirebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "createUserWithEmail: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", task.getException());
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(LoginActivity.this, HomeActivity.class));
finish();
}
}
});
}
示例9: listener
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
/**
* @param emit
* @param <R>
* @return
*/
@NonNull
@CheckReturnValue
public static <R> OnCompleteListener<R> listener(@NonNull final CompletableEmitter emit) {
return new OnCompleteListener<R>() {
@Override
public void onComplete(@NonNull final Task<R> task) {
if (!emit.isDisposed()) {
if (task.isSuccessful()) {
emit.onComplete();
} else {
Exception e = task.getException();
emit.onError(e != null ? e : new RuntimeException());
}
}
}
};
}
示例10: shotenLongLink
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
public void shotenLongLink() {
// [START shorten_long_link]
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(Uri.parse("https://abc123.app.goo.gl/?link=https://example.com/&apn=com.example.android&ibn=com.example.ios"))
.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 shorten_long_link]
}
示例11: removePost
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
public void removePost(final Post post, final OnTaskCompleteListener onTaskCompleteListener) {
final DatabaseHelper databaseHelper = ApplicationHelper.getDatabaseHelper();
Task<Void> removeImageTask = removeImage(post.getImageTitle());
removeImageTask.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
databaseHelper.removePost(post).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
onTaskCompleteListener.onTaskComplete(task.isSuccessful());
databaseHelper.updateProfileLikeCountAfterRemovingPost(post);
LogUtil.logDebug(TAG, "removePost(), is success: " + task.isSuccessful());
}
});
LogUtil.logDebug(TAG, "removeImage(): success");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
LogUtil.logError(TAG, "removeImage()", exception);
onTaskCompleteListener.onTaskComplete(false);
}
});
}
示例12: getSignRequest
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
private void getSignRequest() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS)
== PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "getSignRequest permission is granted");
Task<SignRequestParams> getSignRequestTask = asyncGetSignRequest();
getSignRequestTask.addOnCompleteListener(new OnCompleteListener<SignRequestParams>() {
@Override
public void onComplete(@NonNull Task<SignRequestParams> task) {
SignRequestParams signRequest = task.getResult();
if (signRequest == null) {
Log.i(TAG, "signRequest is null");
return;
}
sendSignRequestToClient(signRequest);
}
});
} else {
Log.i(TAG, "getSignRequest permission is requested");
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.GET_ACCOUNTS},
GET_ACCOUNTS_PERMISSIONS_REQUEST_SIGN);
}
}
示例13: handleFacebookAccessToken
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
private void handleFacebookAccessToken(AccessToken token) {
Log.d(TAG, "handleFacebookAccessToken:" + token);
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
fireBaseAuth.signInWithCredential(credential)
.addOnCompleteListener(getActivity(), 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(getApplicationContext(), "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
示例14: handleAccessToken
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
public void handleAccessToken(AccessToken token) {
Utils.d("FB:Handle:AccessToken: " + token.getToken());
// showProgressDialog();
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Utils.d("FB: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()) {
Utils.w("FB:signInWithCredential" +
task.getException().toString());
}
// hideProgressDialog();
}
});
}
示例15: firebaseAuthWithGoogle
import com.google.android.gms.tasks.OnCompleteListener; //導入依賴的package包/類
/**
* Method firebaseAuthWithGoogle
*
* Authenticates in Firebase through a Google Account.
*/
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(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
else {
startActivity(new Intent(LoginActivity.this, HomeActivity.class));
finish();
}
}
});
}