簡體   English   中英

如何在Android中訪問外部存儲卡

[英]How to access external memory card in Android

我正在Android中創建一個音樂播放器類型的應用程序。

所以我需要找到手機中可用的所有mp3文件,並在ListView中顯示。

所以我想訪問設備的外部存儲卡。

我試試這個,

Environment.getExternalStorageDirectory().getPath()

但是這個代碼指的是設備的內部SD卡而不是外部存儲卡。

那么如何以編程方式訪問設備的外部存儲卡?

提前致謝

首先,您可以獲得這樣的目錄路徑..

File storageDir = new File("/mnt/");
if (storageDir.isDirectory()) {
    String[] dirList = storageDir.list();
    //check here
}

要么

// Internal Storage
new File("/mnt/external_sd/")

// External Storage
new File("/mnt/extSdCard/")

在一些手機中,內部和外部指的是相同的位置

試試這個

if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_MOUNTED)) {

     //use Environment.getExternalStorageDirectory() here

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM