尝试从FirebaseStorage获取公共downloadUrl时出现以下错误。我已经设置了规则以允许完全读写访问,并且将数据存储在存储中没有问题。但是,当我尝试获取下载URL时,我遇到了这个问题。 -
E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.android.gms.internal.zzbtk: Please sign in before trying to get a token.
我已阅读Firebase getDownloadURL 但仍然无法解决我的问题。
这是我的功能 -
@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);
}
});
}
});
}
}
答案 0 :(得分:1)
请在Activity类
的onCreate方法中添加以下代码行 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);
}
});
}
这还不足以解决您的问题。现在添加上面的代码。
打开Firebase Console&gt;点击左侧菜单中的AUTHENTICATION&gt;登录方法&gt;启用匿名 现在构建并运行应用程序,如果没有工作让我知道