The problem when navigating through the resource folder :(

I have a subfolder in the Assets folder, called images, where I store my images (of course) :) The fact is that I want to get a name for the images that I get, but the problem is that I also get other unknown names such as: "android-logo-mask.png", which I think are the default android images. Is there a way I can skip these “default images for Android” to get only the names of my images? My plan is to store these names in a database so that they can be used as a link to display images later in ImageView. Is it a good idea to use an image name to display images? Here is the code for you:

Context context; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this.getApplicationContext(); ImageHelper i = new ImageHelper(); i.readImages(context); } public class ImageHelper { public ImageHelper(){} public void readImages(Context context){ AssetManager am = context.getAssets(); try { String[] getImages = am.list("images"); for(String imgName : getImages){ Log.e("IMAGE NAME----->", imgName); } } catch (IOException e) { e.printStackTrace(); } } } 

Thanks in advance.

+4
source share
4 answers

Use a different name for the image folder, for example "MyImages". Then it should work fine.

+7
source

"images" should be like "/path/assets/images/image.png"

+2
source

If it happens that the system adds files to this "images" folder, why not create a new folder for your images, in which you will definitely contain only your files?

+1
source

It is very interesting. Even if you do not have a resource / image directory when you use:

 myImageList = Arrays.asList(getResources().getAssets().list("images")); 

You will see android-logo-mask.png and android-logo-shine.png listed in the results.

This made me wonder where the real image files in the Android code are. I don’t know the code base at all, but:

https://android.googlesource.com/platform/frameworks/base/+/master/core/res/assets/images/

lists these two in the resource directory under res. (Unlike the resource catalog, which stores my project assets that are not under permission).

The requirement to provide a path to a separate file for the AssetManagers list method (which returns an array) simply does not make any sense. And the documentation for the method says:

Returns a String array of all assets at the given path.

This makes me wonder if there was a mistake in the list method or if there was some other reason, it was intended to return certain system assets when a list of assets is required.

Similarly, if I use:

 myAssetList = Arrays.asList(getResources().getAssets().list("")); 

I see the included “sounds” and “web kit” that do not match any existing subdirectory of my assets.

+1
source

All Articles