use of com.google.android.gms.tasks.OnFailureListener in project FirebaseUI-Android by firebase.
the class WelcomeBackIdpPrompt method onSuccess.
@Override
public void onSuccess(final IdpResponse idpResponse) {
if (idpResponse == null) {
// do nothing
return;
}
AuthCredential newCredential = AuthCredentialHelper.getAuthCredential(idpResponse);
if (newCredential == null) {
Log.e(TAG, "No credential returned");
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
return;
}
FirebaseUser currentUser = mActivityHelper.getCurrentUser();
if (currentUser == null) {
mActivityHelper.getFirebaseAuth().signInWithCredential(newCredential).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult result) {
if (mPrevCredential != null) {
result.getUser().linkWithCredential(mPrevCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with previous credential " + idpResponse.getProviderType())).addOnCompleteListener(new FinishListener(idpResponse));
} else {
finish(ResultCodes.OK, IdpResponse.getIntent(idpResponse));
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
finishWithError();
}
}).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with new credential " + idpResponse.getProviderType()));
} else {
currentUser.linkWithCredential(newCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error linking with credential " + idpResponse.getProviderType())).addOnCompleteListener(new FinishListener(idpResponse));
}
}
use of com.google.android.gms.tasks.OnFailureListener in project FirebaseUI-Android by firebase.
the class CredentialSignInHandler method onComplete.
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser firebaseUser = task.getResult().getUser();
mHelper.saveCredentialsOrFinish(mSmartLock, mActivity, firebaseUser, mResponse);
} else {
if (task.getException() instanceof FirebaseAuthUserCollisionException) {
final String email = mResponse.getEmail();
if (email != null) {
mHelper.getFirebaseAuth().fetchProvidersForEmail(email).addOnFailureListener(new TaskFailureLogger(TAG, "Error fetching providers for email")).addOnSuccessListener(new StartWelcomeBackFlow()).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// TODO: What to do when signing in with Credential fails
// and we can't continue to Welcome back flow without
// knowing providers?
}
});
return;
}
} else {
Log.e(TAG, "Unexpected exception when signing in with credential " + mResponse.getProviderType() + " unsuccessful. Visit https://console.firebase.google.com to enable it.", task.getException());
}
mHelper.dismissDialog();
}
}
use of com.google.android.gms.tasks.OnFailureListener in project quickstart-android by firebase.
the class MainActivity method onStart.
// [END handle_intent]
// [START app_indexing_view]
@Override
public void onStart() {
super.onStart();
if (articleId != null) {
final Uri BASE_URL = Uri.parse("https://www.example.com/articles/");
final String APP_URI = BASE_URL.buildUpon().appendPath(articleId).build().toString();
Indexable articleToIndex = new Indexable.Builder().setName(TITLE).setUrl(APP_URI).build();
Task<Void> task = FirebaseAppIndex.getInstance().update(articleToIndex);
// If the Task is already complete, a call to the listener will be immediately
// scheduled
task.addOnSuccessListener(MainActivity.this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "App Indexing API: Successfully added " + TITLE + " to index");
}
});
task.addOnFailureListener(MainActivity.this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(TAG, "App Indexing API: Failed to add " + TITLE + " to index. " + exception.getMessage());
}
});
// log the view action
Task<Void> actionTask = FirebaseUserActions.getInstance().start(Actions.newView(TITLE, APP_URI));
actionTask.addOnSuccessListener(MainActivity.this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "App Indexing API: Successfully started view action on " + TITLE);
}
});
actionTask.addOnFailureListener(MainActivity.this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(TAG, "App Indexing API: Failed to start view action on " + TITLE + ". " + exception.getMessage());
}
});
}
}
use of com.google.android.gms.tasks.OnFailureListener in project quickstart-android by firebase.
the class MainActivity method onStop.
@Override
public void onStop() {
super.onStop();
if (articleId != null) {
final Uri BASE_URL = Uri.parse("https://www.example.com/articles/");
final String APP_URI = BASE_URL.buildUpon().appendPath(articleId).build().toString();
Task<Void> actionTask = FirebaseUserActions.getInstance().end(Actions.newView(TITLE, APP_URI));
actionTask.addOnSuccessListener(MainActivity.this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "App Indexing API: Successfully ended view action on " + TITLE);
}
});
actionTask.addOnFailureListener(MainActivity.this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(TAG, "App Indexing API: Failed to end view action on " + TITLE + ". " + exception.getMessage());
}
});
}
}
use of com.google.android.gms.tasks.OnFailureListener in project quickstart-android by firebase.
the class MyDownloadService method downloadFromPath.
private void downloadFromPath(final String downloadPath) {
Log.d(TAG, "downloadFromPath:" + downloadPath);
// Mark task started
taskStarted();
showProgressNotification(getString(R.string.progress_downloading), 0, 0);
// Download and get total bytes
mStorageRef.child(downloadPath).getStream(new StreamDownloadTask.StreamProcessor() {
@Override
public void doInBackground(StreamDownloadTask.TaskSnapshot taskSnapshot, InputStream inputStream) throws IOException {
long totalBytes = taskSnapshot.getTotalByteCount();
long bytesDownloaded = 0;
byte[] buffer = new byte[1024];
int size;
while ((size = inputStream.read(buffer)) != -1) {
bytesDownloaded += size;
showProgressNotification(getString(R.string.progress_downloading), bytesDownloaded, totalBytes);
}
// Close the stream at the end of the Task
inputStream.close();
}
}).addOnSuccessListener(new OnSuccessListener<StreamDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(StreamDownloadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "download:SUCCESS");
// Send success broadcast with number of bytes downloaded
broadcastDownloadFinished(downloadPath, taskSnapshot.getTotalByteCount());
showDownloadFinishedNotification(downloadPath, (int) taskSnapshot.getTotalByteCount());
// Mark task completed
taskCompleted();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.w(TAG, "download:FAILURE", exception);
// Send failure broadcast
broadcastDownloadFinished(downloadPath, -1);
showDownloadFinishedNotification(downloadPath, -1);
// Mark task completed
taskCompleted();
}
});
}
Aggregations