AndroidResource File Classification:
Android resource files can be broadly divided into two types:
The first is a compiled resource file that is stored in the Res directory:
This resource file system will automatically generate the ID of the resource file in R.java, so access to this resource file is relatively simple, through the r.xxx.id can be;
The second is a native resource file stored under the assets directory:
Because the system does not compile the resource files under assets, we cannot access them in r.xxx.id way. Can I access them through the absolute path of the resource? Because APK installation will be placed in the/data/app/**.apk directory, in the form of APK, asset/res and is bound to the APK, and will not be extracted into the/data/data/yourapp directory down, So we can't get the absolute path to the assets directly, because they don't have it at all.
Fortunately the Android system provides us with a Assetmanager tool class.
Viewing the official API, Assetmanager provides access to the application's original resource file; This class provides a low-level API that allows you to open and read the raw resource files that are bound together with the application as a simple byte stream.
Assetmanager class Overview:
Provides access to the application's original resource file; This class provides a low-level API that allows you to open and read the raw resource files that are bound together with the application in the form of simple byte streams. Gets the Assetmanager object through the Getassets () method.
Common methods of the Assetmanager class:
Public Methods |
Final string[] |
List (String path) Returns all files and directory names under the specified path. |
Final InputStream |
Open (String fileName) Use access_streaming mode to open the specified file under assets. |
Final InputStream |
Open (String fileName, int accessmode) Opens the specified file under assets using the access mode shown. |
How to access resources in Android projects