chevron_left
0 points
15 11 8

We have already seen in various apps that we can view images saved in sdcard folder in android. And that's really helps in using that allocated sapce by just accessing sdcard folder.

If you want to do the same for your android application and you have no idea about it, then don't worry we will learn together in this article.

Steps

1. Get path
2. Permission
3. Showing in GridView

You can get the path of files from a particular folder as given below and once you got the path of the files you can easily display the images in gridview.

ArrayList<String> f = new ArrayList<String>();// list of file paths
File[] listFile;

public void getFromSdcard()
{
    File file= new File(android.os.Environment.getExternalStorageDirectory(),"TMyFolder");

        if (file.isDirectory())
        {
            listFile = file.listFiles();


            for (int i = 0; i < listFile.length; i++)
            {

                f.add(listFile[i].getAbsolutePath());

            }
        }
}

Remember to add permission manifest file

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

By having write permission will have read permission by default.

Example

More Posts

How to get selected date from datepicker in android amna - May 25
How to get data from sqlite database in android example amna - May 24
How to open all files in a folder amna - Jun 30
How to Get Started with AdMob in Your Android App darshan1507 - Jun 7
How to get current date in android amna - Oct 19, 2020
How to share images on google drive amna - Jun 25
How to upload multiple photos to facebook from android amna - May 19
How to duplicate a folder in google drive amna - Jul 3
How multiple images can be uploaded in the database by using PHP and MYSQL? Farkhanda Athar - May 5, 2020
Auto copy files from one folder to another amna - Jul 4