Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用下载管理器将媒体存储在内部存储器中_Android_Uri_Android Download Manager_Android Internal Storage - Fatal编程技术网

Android 使用下载管理器将媒体存储在内部存储器中

Android 使用下载管理器将媒体存储在内部存储器中,android,uri,android-download-manager,android-internal-storage,Android,Uri,Android Download Manager,Android Internal Storage,要使用Uri将音乐文件存储在GetFileDir()中。我试着用这种方式储存 Uri Download_Uri = Uri.parse(songBean.vSongsFileName); DownloadManager.Request request = new DownloadManager.Request(Download_Uri); mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE)

要使用Uri将音乐文件存储在GetFileDir()中。我试着用这种方式储存

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())抛出
不是文件uri
错误。请帮助我解决此问题

GetFileDir()仅是应用程序的专用内部存储。你不能要求其他应用程序将文件放在那里,因为它没有访问权限


对于DownloadManager,请使用外部存储。

我看不到任何问题说明。也不是一个问题。我面临着这类问题,所以如果有人这样做了,我会发布它。你面临的问题是什么?您没有描述问题。
createDirectory()
。这不会创建目录。您可以使用file.exists()进行检查。
它不会引发文件uri错误。
什么是
?请直截了当地说。是否有任何解决方案将介质存储在内部存储器中?请使用文件提供商。您能为我提供链接或一些建议吗?