我正在使用firebase存储来上传文件,但是当我上传时,我收到此错误
E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.android.gms.internal.zzand: Please sign in before trying to get a token.
解决方法
我认为您在上传文件之前没有签名.在启动器活动的onCreate()中,尝试此代码
FirebaseAuth mAuth = FirebaseAuth.getInstance();
然后在onStart()中,
FirebaseUser user = mAuth.getCurrentUser(); if (user != null) { // do your stuff } else { signInAnonymously(); }
signInAnonymously()
private void signInAnonymously() { mAuth.signInAnonymously().addOnSuccessListener(this,new OnSuccessListener<AuthResult>() { @Override public void onSuccess(AuthResult authResult) { // do your stuff } }) .addOnFailureListener(this,new OnFailureListener() { @Override public void onFailure(@NonNull Exception exception) { Log.e(TAG,"signInAnonymously:FAILURE",exception); } }); }
这可以解决您的问题