【问题标题】:Store media in internal storage using download manager使用下载管理器将媒体存储在内部存储中
【发布时间】:2017-04-15 06:18:18
【问题描述】:

想要使用 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())); throwing not a file uri 错误。请帮我解决这个问题

【问题讨论】:

  • 我看没有问题描述。也不是问题。
  • 我遇到了这种类型的问题,所以如果有人这样做,我会发布它
  • 您遇到了哪个问题?您没有描述问题/问题。
  • createDirectory()。这不会创建目录。您可以使用 file.exists() 进行检查。
  • .It throwing not a file uri error. it 是什么?请言归正传。

标签: android uri android-download-manager android-internal-storage


【解决方案1】:

getFilesDir() 是您的应用专用的内部存储空间。您不能要求其他应用将文件放在那里,因为它无权访问。

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

【讨论】:

  • 有没有办法将媒体存储在内部存储中?
  • 使用 FileProvider。
  • 你能给我建议链接或一些想法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-27
  • 1970-01-01
  • 2012-07-11
  • 1970-01-01
  • 1970-01-01
  • 2012-07-18
  • 2023-03-12
相关资源
最近更新 更多