Android provides assetmanager to access resources under the Asset directory,
Get Assetmanager through Getassets () in activity
The common APIs are as follows:
1, enumerate the resources under the path string[] List (String path)
2. InputStream Open (Resource path under Asset directory)
Here is the code to ask the picture under the Asset directory
Package Com.example.qunzheng.customerview;import Android.app.activity;import Android.content.res.AssetManager; Import Android.graphics.bitmapfactory;import Android.graphics.drawable.bitmapdrawable;import android.os.Bundle; Import Android.view.view;import android.widget.imageview;import java.io.ioexception;import java.io.InputStream; public class Visitassetsresourceactivity extends Activity {private ImageView ImageView; Private string[] images = null; Private Assetmanager Assetmanager; private int curimageindex = 0; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_visit_assets_resource); ImageView = (ImageView) Findviewbyid (r.id.image); Assetmanager = Getassets (); try {images = Assetmanager.list (""); } catch (IOException e) {e.printstacktrace (); }} public void Viewimage (view view) {if (Curimageindex; = images.length) {curimageindex = 0; /** * If the picture resource is not released, release the resource to prevent memory overflow */bitmapdrawable drawable = (bitmapdrawable) imageview.ge Tdrawable (); if (drawable! = null && drawable.getbitmap ()! = null &&!drawable.getbitmap (). isRecycled ()) {D Rawable.getbitmap (). Recycle (); } try {InputStream assertfile = Assetmanager.open (images[curimageindex++]); Imageview.setimagebitmap (Bitmapfactory.decodestream (assertfile)); } catch (IOException e) {e.printstacktrace (); } }}
Android access to resources under the asset directory