Reputation: 969
I'm getting the following error when trying to get the public downloadUrl from FirebaseStorage. I've set my rules to allow full read and write access, and have no problem storing my data in the storage. However, when I try to get the download url, I get this problem. -
E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.android.gms.internal.zzbtk: Please sign in before trying to get a token.
I've read Firebase getDownloadURL but was still unable to resolve my issue.
Here's my function-
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 0 && resultCode == RESULT_OK) {
Uri uri = data.getData();
final StorageReference filePath = mStorage.child("Photos").child(uri.getLastPathSegment());
filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// @SuppressWarnings("VisibleForTests") Uri downloadUri = taskSnapshot.getDownloadUrl();
// recognizeImage(downloadUri);
filePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
recognizeImage(uri);
}
});
}
});
}
}
Upvotes: 0
Views: 3947
Reputation: 2308
Please add the following lines of code inside the onCreate method of Activity class
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
/* perform your actions here*/
} else {
signInAsAnonymous();
}
private void signInAnonymously() {
mAuth.signInAnonymously().addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
/* perform your actions here*/
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e("MainActivity", "signFailed****** ", exception);
}
});
}
This is not enough to resolve your issue. Now after adding the above code.
Open Firebase Console> Click on AUTHENTICATION from left menu > SIGN-IN METHOD > ENABLE ANONYMOUS Now build and run the app if not works let me know
Upvotes: 1