簡體   English   中英

無法訪問Android中下載的文件

[英]Unable to access downloaded files in Android

因此,我使用以下代碼從提供的URL下載.mp3歌曲:

private long DownloadData (Uri uri) {

    long downloadReference;

    // Create request for android download manager
    downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(uri);

    request.setTitle("Data Download");
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | 
            DownloadManager.Request.NETWORK_MOBILE);
    request.setDescription("Android Data download using DownloadManager.");
    request.setDestinationInExternalFilesDir(DownloadSongActivity.this, 
            Environment.DIRECTORY_DOWNLOADS ,"doesn'twork.mp3");

    downloadReference = downloadManager.enqueue(request);

    return downloadReference;
}

然后,我嘗試使用以下代碼讓用戶訪問應用程序中的這些文件

File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
    File[] downloadedFiles = path.listFiles();


    if(downloadedFiles == null){
        System.out.println("DownloadedFiles are null");
    } else if(downloadedFiles.length == 0){
        System.out.println("DownloadedFiles are empty");
    } else{
        System.out.println("DownloadedFiles are not empty");
    }

但是,似乎downloadedFiles始終為空。 有什么建議么。 這是一些圖片供參考

如果我轉到文件->下載

圖片參考鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM