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

你可以建议我链接或一些想法吗? –