Android: How to find the absolute path of the asse

2020-03-01 05:48发布

问题:

I need to get the absolute path of the assets folder in my app as I want to serve the files within using a webserver and it needs the absolute path. Is this possible?

I would have thought there might be something like this:

String rootDir = getAssets().getRootDirectory();

but there's not.

Any help appreciated, cheers.

回答1:

Is this possible?

No. There is no "absolute path of the assets folder in [your] app". Assets are stored in the APK file.

In select cases, such as URLs supplied to a WebView, you can use the special file:///android_asset base URL to reference files in your assets.



回答2:

You can always copy files from the assets directory in the APK to a folder on the device, then serve that folder.