0

想要使用Uri將音樂文件存儲在getFilesDir()中。我曾試圖通過這種方式使用下載管理器將媒體存儲在內部存儲器中

Uri Download_Uri = Uri.parse(songBean.vSongsFileName); 
DownloadManager.Request request = new DownloadManager.Request(Download_Uri); 
mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); 
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE); 
request.setAllowedOverRoaming(false); 
request.setTitle(songBean.vTitle); 
request.setDescription("Downloading File"); 

    try { 
    request.setDestinationUri(Uri.parse(createDirectory("tmp.mp3").getPath())); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 

    request.allowScanningByMediaScanner(); 
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
    downloadReference = mDownloadManager.enqueue(request); 
    registerReceiver(new BroadcastReceiver() { 
     @Override 
     public void onReceive(Context context, Intent intent) { 

     } 
    }, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); 

爲創建目錄的方法存儲內部存儲

public File createDirectory(String filename) throws FileNotFoundException { 
    File file = new File(context.getFilesDir(), filename); 
    Log.i("Tag", "createDirectory: " + file.getAbsolutePath()); 
    return file; 
} 

無法將文件存儲在內部存儲器內。 request.setDestinationUri(Uri.parse(createDirectory("tmp.mp3").getPath()));投擲not a file uri error.Please help out for this

+0

我看沒有問題的描述。也不是一個問題。 – greenapps

+0

我遇到這種類型的問題,所以我發佈它,如果有人已經這樣做 –

+0

你面對哪個問題?你沒有描述一個問題/問題。 – greenapps

回答

0

getFilesDir()是專用於您的應用程序的內部存儲。你不能要求另一個應用程序將文件放在那裏,因爲它沒有訪問權限。

對於DownloadManager使用外部存儲。

+0

是否有任何解決方案將媒體存儲在內部存儲中? –

+0

使用FileProvider。 – greenapps

+0

你可以建議我鏈接或一些想法嗎? –