Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6883075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:20:11+00:00 2026-05-27T05:20:11+00:00

I am trying to get all images in my assets folder using the codes

  • 0

I am trying to get all images in my assets folder using the codes below

private List<String> getImage()
      {
        /* 设定目前所在路径 */
        List<String> it=new ArrayList<String>();      
        File f=new File("file:///android_asset/");  
        File[] files=f.listFiles();
        Log.d("tag", "读取asset资源");

        /* 将所有文件存入ArrayList中 */
        for(int i=0;i<files.length;i++)
        {
          File file=files[i];
          if(getImageFile(file.getPath()))
            it.add(file.getPath());
        }
        return it;

      }

      private boolean getImageFile(String fName)
      {
        boolean re;

        /* 取得扩展名 */
        String end=fName.substring(fName.lastIndexOf(".")+1,
                      fName.length()).toLowerCase(); 

        /* 按扩展名的类型决定MimeType */
        if(end.equals("jpg")||end.equals("gif")||end.equals("png")
                ||end.equals("jpeg")||end.equals("bmp"))
        {
          re=true;
        }
        else
        {
          re=false;
        }
        return re; 
      }

somehow I am not sure about this expression

File f=new File("file:///android_asset/"); 

Well, I know that when read a txt file or html file from assets folder you can use this,but would images accept this too?

I have resolve this problem by using the code below

private List<String> getImage() throws IOException
      {
        AssetManager assetManager = getAssets();
        String[] files = assetManager.list("image");   
        List<String> it=Arrays.asList(files);
        return it; 

        }

in case somebody else want to know

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:20:11+00:00Added an answer on May 27, 2026 at 5:20 am

    In general, you can use the AssetManager to manage files in your asset folder. In the activity, call getAssets () method to get an AssetManager Instance.

    EDIT:
    you can use the AssetManager to read images like this:

    AssetManager am=this.getAssets();
            try {
                Bitmap bmp=BitmapFactory.decodeStream(am.open("009.gif"));
                chosenImageView.setImageBitmap(bmp);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    

    Note that the BitmapFactory.decodeStream() method runs on UI thread by default, so the app would get stuck if the image is too large. In that case, you can change the samplesize or start a new thread to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to get all the images from a facebook group using facebook API
Im trying to get all the ids4's from a list of images in a
I'm trying to get the source attribute of all images withing a specific div
I'm trying to wait and then get a message when all images in an
Good day all; I am trying to manually (not using sublayers) draw images within
I am trying to get recursively load all the assets I have placed within
I'm trying to get all images to be in a horizontal scroller with radio
I’m trying to get a jQuery selector to return all the images that don’t
I'm trying to get the URLs for images (all MIME types) in a remote
I am using simplehtmldom class to get all images from a website, i am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.