简体   繁体   中英

how to get the path of the image(.png) file that is stored in assets folder in android

I have few images in assets folder i want to retrieve the path of the each image file and copy them into array and finally set to image view with some condition. i have used the below code.But it did not workout for me. may i know where i am going wrong.

final Uri ASSETS_URI = Uri.parse("file:///android_asset");
final String[] IMAGE_IDS =new String[] {ASSETS_URI+"/"+"one.png",ASSETS_URI+"/"+"two.png",ASSETS_URI+"/"+"three.png"};

iv=(ImageView)findViewById(R.id.iv);
if(i>=0 & i< IMAGE_IDS.length-1)
   i=i+1;
else if(i==IMAGE_IDS.length-1)
   i=0;

iv.setImageURI(Uri.parse(IMAGE_IDS[i]));

try to change :

    final Uri ASSETS_URI = Uri.parse("file:///android_asset");

to this:

   final String ASSETS_URI = "file:///android_asset";

I think the problem is that you are concatenating and Uri with a String. If you declare ASSETS_URI as String then everything is String and later parsed to Uri.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM