StorageManager類(lèi)中,以下三個(gè)接口都被標(biāo)注為@hide:
getVolumePaths()
返回全部存儲(chǔ)卡路徑, 包括已掛載的和未掛載的.
即: 有外置存儲(chǔ)卡卡槽的機(jī)器,即使未插入外置存儲(chǔ)卡,其路徑也會(huì)被這個(gè)接口列出.
要判斷某個(gè)掛載點(diǎn)的狀態(tài),可以用第三個(gè)接口.
getVolumeList()
返回全部 StorageVolume 類(lèi)的數(shù)組,這個(gè)類(lèi)也是 @hide 的.
該類(lèi)提供了更詳細(xì)的關(guān)于每個(gè)掛載點(diǎn)的信息
getVolumeState(String mountPoint)
返回某個(gè)掛載點(diǎn)代表的存儲(chǔ)卡的狀態(tài). 即 Environment 中的幾個(gè)常量(未全部列出):
獲取所有路徑getVolumePaths() 通過(guò)反射機(jī)制獲取具體掛載信息
protected void openDocumentTree() {
//super.openDocumentTree();
final StorageManager sm = (StorageManager) this.getSystemService(Context.STORAGE_SERVICE);
String[] volumePaths = new String[0];
try {
final Method method = sm.getClass().getMethod("getVolumePaths");
if(null != method) {
method.setAccessible(true);
volumePaths = (String[]) method.invoke(sm);
}
}catch (Exception e){
e.printStackTrace();
}
}
volumePaths[i]即為外部設(shè)備路徑 loadFileByPath加載內(nèi)部數(shù)據(jù)即可