How to search for files on phone sdcard or else where

僤鯓⒐⒋嵵緔 提交于 2019-12-04 21:49:54

问题


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


回答1:


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




回答2:


   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



来源:https://stackoverflow.com/questions/2750395/how-to-search-for-files-on-phone-sdcard-or-else-where

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!