Search code examples
javaandroidbuttoncopymain-activity

Button Click - Copy file from APK Package to Android Path. But How?


Im trying to create a simple application which will copy a file from "assets" folder of the APK Package to (e.g. mnt/sdcard/android/data/com.testdev.testapp when button1 get clicked.

But i don't know how to do this. Is this even Possible or are there any workarounds?

Could anyone help me?

Thanks in advance


Solution

  • Step #1: Call getAssets() on any Context (e.g., your Activity) to get an AssetManager.

    Step #2: Call open() on the AssetManager to get an InputStream on your desired asset.

    Step #3: Use standard Java file I/O to copy from that InputStream to a FileOutputStream pointing at a spot on external storage.