Building a Utility to get the path to External Removable storage every time

时光怂恿深爱的人放手 提交于 2019-11-29 08:00:21

I'm not sure how reliable this would be but since the removable SD card contains the LOST.DIR folder at its root and gets recreated upon boot (in cases where the user might delete it)...

    File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
    for (File sub : root.listFiles()) {
        if (new File(sub + "/lost.dir").exists()) {
            // 'sub' is probably the removable SD
            break;
        }
    }    

If 'sub' is found with a LOST.DIR folder , might want to write its value to sharedPrefs so that this lookup is only performed one time (if there is no value stored) and then just fetched from prefs, OR so that the app knows this path even in case the user deleted LOST.DIR and it currently doesn't exist anywhere.

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