Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search for files on phone sdcard or else where

I want to search for files on the users mobile with specific extensions.

I tried searching but could not find any direct API's.

Is there a specific API's or is there tedious way of achieving the same. Or is there a mechanism to call linux calls for find or something similar

Thanks

like image 679
the100rabh Avatar asked May 01 '10 14:05

the100rabh


2 Answers

   boolean isSDPresent = Environment.getExternalStorageState()
            .equals(Environment.MEDIA_MOUNTED);

    if (isSDPresent) {
        File file[] = Environment.getExternalStorageDirectory().listFiles();
        if (file != null) {
            for (int i = 0; i < file.length; i++) {
                file[i].getAbsolutePath();
            }
        }
    }

Traverse file[] for the required file

like image 118
user936414 Avatar answered Oct 27 '22 01:10

user936414


You can find the user's SD card via Environment.getExternalStorageDirectory(), which you can then traverse to find what you need.

like image 44
CommonsWare Avatar answered Oct 27 '22 00:10

CommonsWare