Both directories can hold files and are preserved as they are packaged.
What can be done with these two directories?
1, put an apk, to use when the tune out, to avoid downloading the server download.
2, put a SQL, when the app database is very large, this can be much easier.
3, put a video, recording, etc., as the start-up introduction, is not very flashy .....
Then ask what to get two directories ....
In fact, assets translated as "resources", raw translation for the "original", and in the Res directory, res name Incredibles, it is under the resources, there are many. such as animations, pictures, XML, IDs, values, etc...
So the popular understanding is
1, assets is for the external resources of the APK is prepared, can be understood as a plug-in directory, it can have a file structure.
2, Raw belongs to the APK's own resources, and will generate its ID in the R file.
Knowing the reasons for their existence, you know that the way to access them is not the same.
Assest: Use Assetmanager to get resources. Getassets () is defined in the context and is used to get assetmanager. As for Assetmanager, it is the list,open of the following method is to read the file.
Raw: It generates an ID in R, which is easier to obtain,getresources (). Openrawresource () is used to get the input stream.
Here's a chat about how to put the APK in raw and install it in the program.
1, copy needs to put the APK placed in the raw directory, renamed to TMP.APK
2. Call the installation method where the installation is required. PS (with the URI of "Android.resource" how can not, seek expert guidance. The simple method provided with the Apache-common-io package is more rapid)
File File = new file (Environment.getexternalstoragedirectory (). GetAbsolutePath () + "/app_tmp.apk"); try { Fileutils.copyinputstreamtofile (Getresources (). Openrawresource (r.raw.tmp), file);} catch (Notfoundexception e) {} catch (IOException e) {}util.install (adddeviceactivity.this, Uri.fromfile (file));
/** * Install an app * @param context * @param filePath need to install file path * @return */public static void Install (context context, URI Uri {Intent i = new Intent (Intent.action_view); I.setdataandtype (URI, "application/vnd.android.package-archive");// I.addflags (Intent.flag_activity_new_task); context.startactivity (i);}
3, the principle is not a look to understand Ah, yes, the input stream output to the SD card and generate a file, the file is passed to the URI can be installed.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Android" Resource series (ii)--the resources assets and Res/raw directories that the files are kept intact