Search code examples
androidassets

Get some asset file path in APK


I use some class. That's constructor needs some file path that contains some files.

ex)

Komoran komoran = new Komoran("D:\program_project\lib");

Now I'm making android app. so I can't use absolute path (Because other people who download my app don't have that folder and files)

so I decide to use 'assets' folder that is maybe in APK file. So, final code is like below.

Komoran komoran = new Komoran("file:///android_asset");

but It seems like folder path is wrong(this class doesn't work). What I did wrong ?


Solution

  • This "file:///android_asset" path is used for applications which uses webview ex. cordova/phonegap. As it is part of resources because when Apk is created you can not use this path to access your assets folder. You have to work with context.getResources().getAssets().open("fileName")this code only.