我正在尝试从Firebase下载文件。我已经完成了从Firebase设置云存储的所有要求,并打开了我的云存储:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}
}
}
我有一个materialButton
,当单击它时,应从云存储下载文件并将其存储在下载目录中。这是我的代码
public class MainActivity extends AppCompatActivity {
MaterialButton mconvertButton;
FirebaseStorage mfirebaseStorage;
StorageReference mstorageReference;
StorageReference ref;
@Override
protected void onCreate(Bundle savedInstanceState) {
mconvertButton = findViewById(R.id.convertButton);
mconvertButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
download();
}
});
}
public void download(){
mstorageReference = FirebaseStorage.getInstance().getReference();
ref = mstorageReference.child("_HDbN_ugHkQ.wav");
ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String url = uri.toString();
downloadFiles(MainActivity.this, "_HDbN_ugHkQ",
".wav", DIRECTORY_DOWNLOADS, url);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
e.printStackTrace();
}
});
}
public void downloadFiles(Context context, String fileName, String fileExtension, String destinationDirectory, String url){
DownloadManager downloadManager = (DownloadManager) context.
getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(context, destinationDirectory, fileName + fileExtension);
}
但是,每次单击按钮,我都会回来:
W/StorageUtil: no auth token for request
W/NetworkRequest: no auth token for request
我已尝试清除我的应用程序数据,已尝试卸载并重新安装我的应用程序。我多次检查我的应用程序仍连接到Firebase,但问题仍然存在。您对如何解决此问题有任何想法吗?
日志详细信息
问题已解决。我忘记将downloadManager.enqueue(request);
添加到我的downloadFiles
函数中。