How to search for files on phone sdcard or else wh

2020-06-17 15:22发布

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

2条回答
女痞
2楼-- · 2020-06-17 15:37

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

查看更多
We Are One
3楼-- · 2020-06-17 15:44
   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

查看更多
登录 后发表回答