導航:首頁 > 操作系統 > android獲得sd卡路徑

android獲得sd卡路徑

發布時間:2022-10-03 18:21:52

android中如何獲得外置sd卡的路徑和手機自身內存的路徑

有些沒看
懂你
的意思,一般手機能夠自己明白SD卡和內置存儲的。如果你要設置路徑的話。一般會以sdcard1、sdcard2來作為路徑。

㈡ 如何獲得在Android的內部和外部SD卡路徑

首先我要說的是,你的三星手機,和小米手機,不能寫為//sdcard//... 這個系統重新封裝了,不能用簡寫。 String mPath = Environment.getExternalStorageDirectory().toString(); 獲得路徑字元串。 至於其他參數的,都是輔助

㈢ 獲取android手機的自帶存儲路徑和sdcard存儲路徑

android手機獲取自帶存儲來路徑和sd卡存儲路徑的方式是:調用Environment.getExternalStorageDirectory(),返回的存儲源目錄並不是系統內置的SD卡目錄。
1.一部分手機將eMMC存儲掛載到
/mnt/external_sd
、/mnt/sdcard2
等節點知,而將外置的SD卡掛載到
Environment.getExternalStorageDirectory()這個結點。
此時,調用Environment.getExternalStorageDirectory(),則返回外置的SD的路徑。
2.而另一部分手機直接道將eMMC存儲掛載在Environment.getExternalStorageDirectory()這個節點,而將真正的外置SD卡掛載到/mnt/external_sd、/mnt/sdcard2
等節點。
此時,調用Environment.getExternalStorageDirectory(),則返回內置的SD的路徑。

㈣ Android SD卡路徑問題以及如何獲取SDCard 內存詳解

較好的方法是通過Environment
來獲取路徑,最後給出一個例子,教你怎樣獲取SDCard
的內存,顯示出來告訴用戶。講述的內容如下:0202
0、獲取sd卡路徑。
1、講述
Environment
類。
2、講述
StatFs
類。
3、完整例子讀取
SDCard
內存
0、獲取sd卡路徑
方法一:
private
String
folder
=
"/sdcard/DCIM/Camera/"(SD卡上拍照程序的圖片存儲路徑);
//寫死絕對路徑,不贊成使用方法二:

㈤ 安卓手機sd卡的路徑在哪

【手機存儲路徑】描述方法:

方法一:/storage/sdcard0/所在文件夾名/文件名

方法二:/mnt/sdcard/所在文件夾名/文件名

【擴展SD卡路徑】描述方法:

方法一:/storage/sdcard1/所在文件夾名/文件名

方法二:/mnt/sdcard2/所在文件夾名/文件名

有的手機存儲支持兩類,一個是手機存儲,另一個是擴展SD卡(打開你的手機文件管理器,就能看到你的手機支持哪些了)『

有些手機因為手機存儲容量達到16G,32G,甚至更高等等,就不支持擴展SD卡(有指甲蓋大小的,需要卡槽存放的小卡)。

拓展資料;

SD存儲卡是一種基於半導體快閃記憶器的新一代記憶設備,由於它體積小、數據傳輸速度快、可熱插拔等優良的特性,被廣泛地於攜帶型裝置上使用,例如數碼相機、個人數碼助理(外語縮寫PDA)和多媒體播放器等。

SD卡應用於以下的手提數碼裝置:

數碼相機

儲存相片及短片

數碼攝錄機儲存相片及短片

個人數碼助理(PDA)儲存各類資料

手提電話儲存相片、鈴聲、音樂、短片等資料

多媒體播放器

SD卡多用於MP3隨身聽、數碼攝像機、數碼相機等,也有用於筆記本電腦上。SD卡在2013年的發展很快,已經開始威脅到CF卡的市場份額了。不過注意的是,在某些產品例如手機上,SD卡和MMC卡是不能兼容的。2013年的SD卡容量由8MB到128GB不等。

參考鏈接;網路-SD卡

㈥ 如何正確獲得Android內外SD卡路徑

/**
* 獲取手機自身內存路徑
*
*/
public static String getPhoneCardPath(){
return Environment.getDataDirectory().getPath();
}
/**
* 獲取sd卡路徑
* 雙sd卡時,根據」設置「裡面的數據存儲位置選擇,獲得的是內置sd卡或外置sd卡
* @return
*/
public static String getNormalSDCardPath(){
return Environment.getExternalStorageDirectory().getPath();
}
/**
* 獲取sd卡路徑
* 雙sd卡時,獲得的是外置sd卡
* @return
*/
public static String getSDCardPath() {
String cmd = "cat /proc/mounts";
Runtime run = Runtime.getRuntime();// 返回與當前 Java 應用程序相關的運行時對象
BufferedInputStream in=null;
BufferedReader inBr=null;
try {
Process p = run.exec(cmd);// 啟動另一個進程來執行命令
in = new BufferedInputStream(p.getInputStream());
inBr = new BufferedReader(new InputStreamReader(in));

String lineStr;
while ((lineStr = inBr.readLine()) != null) {
// 獲得命令執行後在控制台的輸出信息
Log.i("CommonUtil:getSDCardPath", lineStr);
if (lineStr.contains("sdcard")
&& lineStr.contains(".android_secure")) {
String[] strArray = lineStr.split(" ");
if (strArray != null && strArray.length >= 5) {
String result = strArray[1].replace("/.android_secure",
"");
return result;
}
}
// 檢查命令是否執行失敗。
if (p.waitFor() != 0 && p.exitValue() == 1) {
// p.exitValue()==0表示正常結束,1:非正常結束
Log.e("CommonUtil:getSDCardPath", "命令執行失敗!");
}
}
} catch (Exception e) {
Log.e("CommonUtil:getSDCardPath", e.toString());
//return Environment.getExternalStorageDirectory().getPath();
}finally{
try {
if(in!=null){
in.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if(inBr!=null){
inBr.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return Environment.getExternalStorageDirectory().getPath();
}
//查看所有的sd路徑
public String getSDCardPathEx(){
String mount = new String();
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("secure")) continue;
if (line.contains("asec")) continue;

if (line.contains("fat")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
mount = mount.concat("*" + columns[1] + "\n");
}
} else if (line.contains("fuse")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
mount = mount.concat(columns[1] + "\n");
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mount;
}
//獲取當前路徑,可用空間
public static long getAvailableSize(String path){
try{
File base = new File(path);
StatFs stat = new StatFs(base.getPath());
long nAvailableCount = stat.getBlockSize() * ((long) stat.getAvailableBlocks());
return nAvailableCount;
}catch(Exception e){
e.printStackTrace();
}
return 0;
}

㈦ 獲取android手機的自帶存儲路徑和sdcard存儲路徑

android手機獲取自帶存儲路徑和sd卡存儲路徑的方式是:調用Environment.getExternalStorageDirectory(),返回的存儲目錄並不是系統內置的SD卡目錄。
1.一部分手機將eMMC存儲掛載到
/mnt/external_sd
、/mnt/sdcard2
等節點,而將外置的SD卡掛載到
Environment.getExternalStorageDirectory()這個結點。
此時,調用Environment.getExternalStorageDirectory(),則返回外置的SD的路徑。
2.而另一部分手機直接將eMMC存儲掛載在Environment.getExternalStorageDirectory()這個節點,而將真正的外置SD卡掛載到/mnt/external_sd、/mnt/sdcard2
等節點。
此時,調用Environment.getExternalStorageDirectory(),則返回內置的SD的路徑。

㈧ android4.0後怎麼獲取sdcard的路徑(包括外置和內置的)

getExternalStorageDirectory()方法在4.0以後只能獲取內置SD卡路徑
外置SD卡
/**
* 獲取外置SD卡路徑
* @return 應該就一條記錄或空
*/
public List<string> getExtSDCardPath()
{
List<string> lResult = new ArrayList<string>();
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
if (line.contains("extSdCard"))
{
String [] arr = line.split(" ");
String path = arr[1];
File file = new File(path);
if (file.isDirectory())
{
lResult.add(path);
}
}
}
isr.close();
} catch (Exception e) {
}
return lResult;
}

List<string> extPaths = getExtSDCardPath();
for (String path : extPaths) {
log.append("外置SD卡路徑:" + path + "\r\n");
}

PS別忘記添加許可權,內外置SD卡的許可權在4.0以後是不一樣的

㈨ 如何正確獲得Android內外SD卡路徑

/** * 獲取手機自身內存路徑 * */ public static String getPhoneCardPath(){ return Environment.getDataDirectory().getPath(); } /** * 獲取sd卡路徑 * 雙sd卡時,根據」設置「裡面的數據存儲位置選擇,獲得的是內置sd卡或外置sd卡 * @return */ public static String getNormalSDCardPath(){ return Environment.getExternalStorageDirectory().getPath(); } /** * 獲取sd卡路徑 * 雙sd卡時,獲得的是外置sd卡 * @return */ public static String getSDCardPath() { String cmd = "cat /proc/mounts"; Runtime run = Runtime.getRuntime();// 返回與當前 Java 應用程序相關的運行時對象 BufferedInputStream in=null; BufferedReader inBr=null; try { Process p = run.exec(cmd);// 啟動另一個進程來執行命令 in = new BufferedInputStream(p.getInputStream()); inBr = new BufferedReader(new InputStreamReader(in)); String lineStr; while ((lineStr = inBr.readLine()) != null) { // 獲得命令執行後在控制台的輸出信息 Log.i("CommonUtil:getSDCardPath", lineStr); if (lineStr.contains("sdcard") && lineStr.contains(".android_secure")) { String[] strArray = lineStr.split(" "); if (strArray != null && strArray.length >= 5) { String result = strArray[1].replace("/.android_secure", ""); return result; } } // 檢查命令是否執行失敗。 if (p.waitFor() != 0 && p.exitValue() == 1) { // p.exitValue()==0表示正常結束,1:非正常結束 Log.e("CommonUtil:getSDCardPath", "命令執行失敗!"); } } } catch (Exception e) { Log.e("CommonUtil:getSDCardPath", e.toString()); //return Environment.getExternalStorageDirectory().getPath(); }finally{ try { if(in!=null){ in.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { if(inBr!=null){ inBr.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return Environment.getExternalStorageDirectory().getPath(); } //查看所有的sd路徑 public String getSDCardPathEx(){ String mount = new String(); try { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("mount"); InputStream is = proc.getInputStream(); InputStreamReader isr = new InputStreamReader(is); String line; BufferedReader br = new BufferedReader(isr); while ((line = br.readLine()) != null) { if (line.contains("secure")) continue; if (line.contains("asec")) continue; if (line.contains("fat")) { String columns[] = line.split(" "); if (columns != null && columns.length > 1) { mount = mount.concat("*" + columns[1] + "\n"); } } else if (line.contains("fuse")) { String columns[] = line.split(" "); if (columns != null && columns.length > 1) { mount = mount.concat(columns[1] + "\n"); } } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return mount; } //獲取當前路徑,可用空間 public static long getAvailableSize(String path){ try{ File base = new File(path); StatFs stat = new StatFs(base.getPath()); long nAvailableCount = stat.getBlockSize() * ((long) stat.getAvailableBlocks()); return nAvailableCount; }catch(Exception e){ e.printStackTrace(); } return 0; }

㈩ android怎麼獲取sd卡的路徑

鏈接電腦USB調試情況下,在電腦上有新的磁碟顯示,一個SD的,一個手機的,打開SD的就可以找各文件夾路徑

閱讀全文

與android獲得sd卡路徑相關的資料

熱點內容
開源文件伺服器加密 瀏覽:587
哈利波特游戲選什麼伺服器 瀏覽:423
雲伺服器怎樣格式化 瀏覽:15
框架柱頂部箍筋加密區規范 瀏覽:168
pythonjson文件讀取 瀏覽:104
夢幻西遊源碼架設 瀏覽:123
抽煙有解壓效果嗎 瀏覽:826
由於加密數據錯誤這個會話將結束 瀏覽:831
javaproject運行 瀏覽:254
0經驗轉行單片機 瀏覽:637
什麼叫解壓縮下載的文件 瀏覽:861
什麼牌子的手機加密狗好用 瀏覽:535
程序員編程學習筆記 瀏覽:863
吃雞亞服怎麼選擇不了伺服器 瀏覽:657
數控設備宏程序編程 瀏覽:839
高速銑編程培訓 瀏覽:649
天正改命令 瀏覽:772
路由器域名伺服器地址怎麼填 瀏覽:87
外掛編譯環境用什麼 瀏覽:216
華為雲伺服器最新價格 瀏覽:853