Android獲取內置sdcard跟外置sdcard路徑
更新時間:2017年09月09日 08:48:27 作者:安輝就是我
這篇文章主要介紹了Android獲取內置sdcard跟外置sdcard路徑的相關資料,希望通過本文能幫助到大家,需要的朋友可以參考下
Android獲取內置sdcard跟外置sdcard路徑
Android獲取內置sdcard跟外置sdcard路徑.(測試過兩個手機,親測可用)
1.先得到外置sdcard路徑,這個接口是系統(tǒng)提供的標準接口.
2.得到上一級文件夾目錄
3.得到該目錄的所有文件夾,根據判斷得到內置sdcard跟外置sdcard。
4.程序運行的時候記得給程序添加讀取sdcard的權限哦.
/**
* 得到sdcard的路徑
* @return 返回一個字符串數組 下標0:內置sdcard 下標1:外置sdcard
*/
public static String[] getSDCardPath(){
String[] sdCardPath=new String[2];
File sdFile=Environment.getExternalStorageDirectory();
File[] files=sdFile.getParentFile().listFiles();
for(File file:files){
if(file.getAbsolutePath().equals(sdFile.getAbsolutePath())){//外置
sdCardPath[1]=sdFile.getAbsolutePath();
}else if(file.getAbsolutePath().contains("sdcard")){//得到內置sdcard
sdCardPath[0]=file.getAbsolutePath();
}
}
return sdCardPath;
}
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
Android使用百度地圖出現閃退及定位時顯示藍屏問題的解決方法
這篇文章主要介紹了Android使用百度地圖出現閃退及定位時顯示藍屏問題的解決方法,需要的朋友可以參考下2018-01-01
關于AndroidStudio R文件莫名其妙缺失的快速解決方法
下面小編就為大家?guī)硪黄P于AndroidStudio R文件莫名其妙缺失的快速解決方法。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03
Android獲取SDcard目錄及創(chuàng)建文件夾的方法
今天小編就為大家分享一篇Android獲取SDcard目錄及創(chuàng)建文件夾的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08

