本文整理了Java中com.google.android.gms.tasks.Task.addOnFailureListener()
方法的一些代码示例,展示了Task.addOnFailureListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.addOnFailureListener()
方法的具体详情如下:
包路径:com.google.android.gms.tasks.Task
类名称:Task
方法名:addOnFailureListener
暂无
代码示例来源:origin: commonsguy/cw-omnibus
@SuppressLint("MissingPermission")
private void findLocation() {
request=buildLocationRequest();
client.requestLocationUpdates(request, cb, Looper.getMainLooper())
.addOnFailureListener(this, e -> {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
Log.e(getClass().getSimpleName(), "Exception getting location", e);
});
}
代码示例来源:origin: commonsguy/cw-omnibus
@SuppressLint("MissingPermission")
private void findLocation() {
FusedLocationProviderClient client=
LocationServices.getFusedLocationProviderClient(this);
client.getLastLocation()
.addOnCompleteListener(this, this::useResult)
.addOnFailureListener(this, this::copeWithFailure);
}
代码示例来源:origin: survivingwithandroid/Surviving-with-android
private void getConnection(String endpointId) {
Nearby.getConnectionsClient(ctx)
.requestConnection(endpointId, endpointId,connectionLifecycleCallback)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "Requesting connection..");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Error requesting connection", e);
}
});
}
代码示例来源:origin: survivingwithandroid/Surviving-with-android
public NearbyDsvManager(Context ctx, final EventListener listener) {
this.listener = listener;
this.ctx = ctx;
Log.i(TAG, "NearbyDsvManager");
Nearby.getConnectionsClient(ctx)
.startDiscovery(SERVICE_ID,
endpointDiscoveryCB,
new DiscoveryOptions(Strategy.P2P_STAR))
.addOnSuccessListener(
new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.i(TAG, "OnSuccess...");
listener.startDiscovering();
}
}
)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "OnFailure", e);
e.printStackTrace();
}
});
}
代码示例来源:origin: survivingwithandroid/Surviving-with-android
public NearbyAdvManager(Context ctx, EventListener listener) {
Log.d(TAG, "Constructor..");
this.ctx = ctx;
this.listener = listener;
client = Nearby.getConnectionsClient(ctx);
client.startAdvertising("AndroidThings",
SERVICE_ID,
connectionLifeCycleCB,
new AdvertisingOptions(Strategy.P2P_STAR))
.addOnSuccessListener(
new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.i(TAG, "OnSuccess...");
}
}
)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "OnFailure 1");
e.printStackTrace();
}
});
}
代码示例来源:origin: gsuitedevs/android-samples
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ConflictResolver.CONFLICT_RESOLVED)) {
Log.d(TAG, "Received intent to update edit text.");
showMessage(getString(R.string.reload_after_conflict));
loadContents(mGroceryListFile).addOnFailureListener(e -> {
Log.e(TAG, "Unexpected error", e);
showMessage(getString(R.string.unexpected_error));
});
}
}
};
代码示例来源:origin: FrangSierra/RxFirebase
@Override
public void subscribe(@NonNull final CompletableEmitter e) throws Exception {
ref.setValue(value).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
e.onComplete();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
if (!e.isDisposed())
e.onError(exception);
}
});
}
});
代码示例来源:origin: FrangSierra/RxFirebase
public static <T> void assignOnTask(MaybeEmitter<? super T> emitter, Task<T> task) {
RxHandler handler = new RxHandler(emitter);
task.addOnSuccessListener(handler);
task.addOnFailureListener(handler);
try {
task.addOnCompleteListener(handler);
} catch (Throwable t) {
// ignore
}
}
代码示例来源:origin: FrangSierra/RxFirebase
public static <T> void assignOnTask(CompletableEmitter completableEmitter, Task<T> task) {
RxCompletableHandler handler = new RxCompletableHandler(completableEmitter);
task.addOnFailureListener(handler);
task.addOnSuccessListener(handler);
try {
task.addOnCompleteListener(handler);
} catch (Throwable t) {
// ignore
}
}
代码示例来源:origin: nmoskalenko/RxFirebase
public static <T> void assignOnTask(Subscriber<? super T> observer, Task<T> task) {
RxTask handler = new RxTask(observer);
task.addOnSuccessListener(handler);
task.addOnFailureListener(handler);
try {
task.addOnCompleteListener(handler);
} catch (Throwable t) {
// ignore
}
}
代码示例来源:origin: nmoskalenko/RxFirebase
private <T> void setupTask(Task<T> task) {
when(task.addOnCompleteListener(testOnCompleteListener.capture())).thenReturn(task);
when(task.addOnSuccessListener(testOnSuccessListener.capture())).thenReturn(task);
when(task.addOnFailureListener(testOnFailureListener.capture())).thenReturn(task);
}
代码示例来源:origin: nmoskalenko/RxFirebase
private <T> void setupTask(Task<T> task) {
when(task.addOnCompleteListener(testOnCompleteListener.capture())).thenReturn(task);
when(task.addOnSuccessListener(testOnSuccessListener.capture())).thenReturn(task);
when(task.addOnFailureListener(testOnFailureListener.capture())).thenReturn(task);
}
代码示例来源:origin: FrangSierra/RxFirebase
static <T> void setupTask(Task<T> task) {
when(task.addOnCompleteListener(testOnCompleteListener.capture())).thenReturn(task);
when(task.addOnSuccessListener(testOnSuccessListener.capture())).thenReturn(task);
when(task.addOnFailureListener(testOnFailureListener.capture())).thenReturn(task);
}
代码示例来源:origin: FrangSierra/RxFirebase
@Override
public void subscribe(final SingleEmitter<HttpsCallableResult> emitter) {
functions.getHttpsCallable(name)
.call(data)
.addOnSuccessListener(new OnSuccessListener<HttpsCallableResult>() {
@Override
public void onSuccess(HttpsCallableResult httpsCallableResult) {
emitter.onSuccess(httpsCallableResult);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
emitter.onError(e);
}
});
}
});
代码示例来源:origin: codeka/wwmmo
public GmsTask(TaskRunner taskRunner, com.google.android.gms.tasks.Task<R> gmsTask) {
super(taskRunner);
gmsTask.addOnFailureListener(this::onError);
gmsTask.addOnCompleteListener(task -> {
try {
this.onComplete(task.getResult());
} catch (Exception e) {
onError(e);
}
});
}
}
代码示例来源:origin: gsuitedevs/android-samples
@Override
protected void onDriveClientReady() {
getDriveClient()
.requestSync()
.continueWithTask(task -> initializeGroceryList())
.addOnFailureListener(e -> {
Log.e(TAG, "Unexpected error", e);
showMessage(getString(R.string.unexpected_error));
});
}
代码示例来源:origin: UdacityAndroidDevScholarship/quiz-app
private void updateUserProperty(String property, String value, final Callback<Void> callback) {
try {
if (mCurrentUser == null) {
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
}
mUsersRef.child(mCurrentUser.getUid()).child(property).setValue(value)
.addOnCompleteListener(task -> callback.onReponse(null))
.addOnFailureListener(e -> callback.onError());
} catch (Exception e) {
e.printStackTrace();
callback.onError();
}
}
}
代码示例来源:origin: UdacityAndroidDevScholarship/quiz-app
@Override
public void updateQuizBookmarkStatus(String quizIdentifier, boolean isBookmarked, Callback<Void> callback) {
if (mCurrentUser == null) {
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
}
mUsersRef.child(mCurrentUser.getUid()).child(KEY_USER_BOOKMARKS).child(quizIdentifier)
.setValue(isBookmarked)
.addOnSuccessListener(aVoid -> callback.onReponse(null))
.addOnFailureListener(e -> callback.onError());
}
代码示例来源:origin: UdacityAndroidDevScholarship/quiz-app
@Override
public void updateMyAttemptedQuizzes(QuizAttempted quizAttempt, Callback<Void> callback) {
if (mCurrentUser == null) {
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
}
mUsersRef.child(mCurrentUser.getUid())
.child(KEY_USER_ATTEMPTED_QUIZ)
.child(quizAttempt.getQuizId())
.setValue(quizAttempt)
.addOnSuccessListener(aVoid -> callback.onReponse(null))
.addOnFailureListener(e -> callback.onError());
}
代码示例来源:origin: UdacityAndroidDevScholarship/quiz-app
@Override
public void postComment(String discussionId, String quizId, Comment comment,
Callback<Void> callback) {
if (mCurrentUser == null) {
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
}
comment.setCommenterId(mCurrentUser.getUid());
mDiscussionsRef.child(quizId).push().setValue(comment)
.addOnSuccessListener(aVoid -> {
callback.onReponse(null);
})
.addOnFailureListener(e -> {
callback.onError();
});
}
内容来源于网络,如有侵权,请联系作者删除!