Java 是否从资产文件夹下载文件?(安卓工作室)

Java 是否从资产文件夹下载文件?(安卓工作室),java,android,Java,Android,我正在制作一个soundboard应用程序,我希望用户能够从资产下载文件,以便他们可以将其设置为通知声音/铃声。我收到一个错误,说我只能从HTTP/HTTPS下载文件。有办法解决这个问题吗 DownloadManager.Request request = new DownloadManager.Request(Uri.parse("content://com.thingy.app/" + filename)); request.setDescription("Soundbite from ")

我正在制作一个soundboard应用程序,我希望用户能够从资产下载文件,以便他们可以将其设置为通知声音/铃声。我收到一个错误,说我只能从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);

使用
AssetManager
并获取资产内容上的
InputStream
。然后,将字节复制到要创建的文件上的
FileOutputStream

我使用它将SQLite数据库从资产文件夹复制到内部存储:

        //Open your local db as the input stream
    InputStream myInput = myContext.getAssets().open(DB_IN);

    // Path to the just created empty db
    String outFileName = DB_PATH + DB_NAME;

    //Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);

    //transfer bytes from the input file to the output file
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer))>0){
        myOutput.write(buffer, 0, length);
    }

    //Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();