2013-06-04 46 views
1

我面臨存儲卡存在與否的一些奇怪問題。我正在檢查IsSDCARD在我的google nexus設備上呈現它的returing true,但是當我嘗試使用文件資源管理器訪問存儲卡時,它在mnt文件夾中顯示沒有存儲卡(存儲卡之前的arrao不存在)....此處是我的代碼,請幫助存儲卡不存在靜止存儲器檢查返回true

public static boolean isSDCardMounted() { 
    Boolean isSDPresent = android.os.Environment.getExternalStorageState() 
      .equals(android.os.Environment.MEDIA_MOUNTED); 
    Log.d("Tag", "SDCARD PRESENT....." + isSDPresent); 
    return isSDPresent; 
} 

if (!DownLoadFile.isSDCardMounted()) { 
      CommonFunctions.showAlerts(MainActivity.this, 
        "SD Card Not Available"); 
      if (progressDialog.isShowing()) 
       progressDialog.dismiss(); 
      cancel(true); 
     } 

請幫助.....

+0

變化getExternalStorageDirectory() – Sam

+0

檢查返回值isExternalStorageRemovable(),檢查我的答案的解釋。 – Tarun

回答

1

檢查

public static boolean isExternalStorageRemovable() 

在API級別9

返回主「外部」存儲設備是否可移除。 如果返回true,則此設備是例如用戶可以刪除的SD卡。如果返回false,則該存儲內置於 設備中,並且不能被物理移除。

Environment.getExternalStorageDirectory()指設備製造商認爲是「外部存儲」的任何設備。在某些設備上,這是可移動媒體,如SD卡。在某些設備上,這是在設備上的閃光 更多的有關此已經通過@CommonsWare回答這裏https://stackoverflow.com/a/5695129/786337

https://stackoverflow.com/a/15612964/786337

0

使用下面線 使用Environment.getExternalStorageState()如在描述"Using the External Storage"的部分。

要獲得外部存儲上的可用空間,使用StatFs

// do this only *after* you have checked external storage state: 
File extdir = Environment.getExternalStorageDirectory(); 
File stats = new StatFs(extdir.getAbsolutePath()); 
int availableBytes = stats.getAvailableBlocks() * stats.getBlockSize(); 

的代碼檢查存儲卡的所有細節提及下面 http://sapienmobile.com/?p=204