Pack files in apk?

I have some files that should be used by my application when it is on the device. Right now, I can only do this by copying these files and pasting them into the device directly using a computer manually.

So, is there a way to pack or copy these files in apk and when installing on the device, and the Program inserts them to automatically indicate the folder on the device.

The files I want to pack are the sphinx speech recognition model

Thanks.

+4
source share
1 answer

You can put the files in the / assets directory of your project, which will build it directly in apk, and then access the file to copy it or what you need using the getAssets() method for the Context object at runtime:

 InputStream input = context.getAssets().open("your_file_name"); String outPath = "/some/path/your_file_name"; OutputStream output = new FileOutputStream(outPath); // transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer)) > 0) { output.write(buffer, 0, length); } // Close the streams output.flush(); output.close(); input.close(); 
+4
source

Source: https://habr.com/ru/post/1403193/


All Articles