首页 > 解决方案 > DownloadManager 来自资产文件夹的文件?(安卓工作室)

问题描述

我正在制作一个音板应用程序,我希望用户能够从资产下载文件,以便他们可以将其设置为通知声音/铃声。我收到一条错误消息,提示我只能从 HTTP/HTTPS 下载文件。有没有解决的办法?

DownloadManager.Request request = new DownloadManager.Request(Uri.parse("content://com.thingy.app/" + filename));
request.setDescription("Soundbite from ");
request.setTitle(filename);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);

标签: javaandroid

解决方案


使用AssetManager及其方法来获取资产open()InputStream内容。然后,将字节复制到FileOutputStream要创建的文件上。


推荐阅读