雖然我有這麼多的帖子,但問題是, 它返回true,如果手機有建立存儲。 任何人幫我檢查SD卡是否可用或編程方式在Android
0
A
回答
1
使用這樣的:
Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
if(isSDPresent)
{
// yes SD-card is present
}
else
{
// Sorry
}
0
下面的代碼將有助於...
/**
* Returns all available external SD-Card roots in the system.
*
* @return paths to all available external SD-Card roots in the system.
*/
public static String[] getStorageDirectories() {
String[] storageDirectories;
String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
List<String> results = new ArrayList<String>();
File[] externalDirs = myContext.getExternalFilesDirs(null);
for (File file : externalDirs) {
String path = null;
try {
path = file.getPath().split("/Android")[0];
} catch (Exception e) {
e.printStackTrace();
path = null;
}
if (path != null) {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Environment.isExternalStorageRemovable(file))
|| rawSecondaryStoragesStr != null && rawSecondaryStoragesStr.contains(path)) {
results.add(path);
}
}
}
storageDirectories = results.toArray(new String[0]);
} else {
final Set<String> rv = new HashSet<String>();
if (!TextUtils.isEmpty(rawSecondaryStoragesStr)) {
final String[] rawSecondaryStorages = rawSecondaryStoragesStr.split(File.pathSeparator);
Collections.addAll(rv, rawSecondaryStorages);
}
storageDirectories = rv.toArray(new String[rv.size()]);
}
return storageDirectories;
}
//檢查外部SD是否可用
String retArray[] = getStorageDirectories();
if (retArray.length == 0) {
Toast.makeText(ListenActivity.this, "Sdcard not Exists", Toast.LENGTH_SHORT).show();
} else {
for (int i = 0; i < retArray.length; i++) {
Log.e("path ", retArray[i]);
}
}
相關問題
- 1. 檢查SD卡是否可用或不在設備編程的Windows Phone芒果
- 2. 檢查sd卡的可用性android
- 3. 檢查SD卡上是否有足夠的內存編程
- 4. 如何找到SD卡是否可用或不在android
- 5. 我想檢查手機是否包含SD卡,如果SD卡不可用,以下方法總是返回true
- 6. Android:檢查文件是否存在於文件夾中或不在SD卡中
- 7. 檢查Android上的SD卡上是否存在文件
- 8. 是否有可能以編程方式將文件推送到無線SD卡?
- 9. 檢查一個SQL服務器是否可用編程方式?
- 10. 檢查Android的SD卡上是否有目錄
- 11. 以編程方式檢測SD卡寫入保護
- 12. 如何以編程方式檢查應用程序是否安裝在Android中?
- 13. 以編程方式檢查在Windows上是否啓用了IPv6
- 14. 如何檢查QQ(tencent)應用程序是否安裝在Android上或不是以編程方式安裝?
- 15. Android。沒有SD卡可用
- 16. 如何檢查SD卡插入Android?
- 17. Android 2.2 - 如何檢測我是否安裝在SD卡上?
- 18. 如何檢查插入的SD卡是否被寫保護或不在Qt中?
- 19. 以編程方式檢查android版本
- 20. Android:如何檢查一個文件是否存在於我的SD卡上
- 21. 在Android 2.x中是否有文檔檢查多個SD卡的內容?
- 22. 如何以編程方式檢查是否安裝使用Java
- 23. 如何檢查藍牙是否以編程方式啓用?
- 24. 檢查用戶是否允許以編程方式截斷表
- 25. 以編程方式檢查Windows是否用C++激活
- 26. 以編程方式檢查iPhone是否已啓用GPS
- 27. 以編程方式檢查是否使用CSS文件
- 28. 以編程方式檢查Oracle AQ隊列是否存在
- 29. 檢查是否以英文字典編程方式在C#
- 30. 如何以編程方式檢查Zookeeper是否正在運行
Android SDK沒有這方面的內容,因爲Android不支持[可移動存儲](http://commonsware.com/blog/2 014/04/09/storage-situation-removable-storage.html),並且4.4+中的支持不包括您正在尋找的內容。 – CommonsWare 2014-12-09 12:54:41