如果存在,如何检查内部和外部存储

我怎么知道在Android的内部和外部存储实用? 没有人知道如何检查内部和外部存储

提前致谢

  • caching与数据存储下载的内容
  • Android:在卸载时从外部存储删除应用关联的文件?
  • Android的SharedPreferences限制?
  • 在SharedPreferences中存储一个String数组
  • 如何衡量Android应用程序数据大小和识别存储泄漏?
  • 存储RSA私钥Android
  • 在Android设备上创build和存储日志文件
  • Android模拟器内部存储在哪里?
  • 它已经在android文档中解释。

    代码来自文件

    boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = mExternalStorageWriteable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = true; mExternalStorageWriteable = false; } else { // Something else is wrong. It may be one of many other states, but all we need // to know is we can neither read nor write mExternalStorageAvailable = mExternalStorageWriteable = false; } 

    我写了一个小class来检查存储状态。 也许这对你有一些用处。

    更新: 清理代码,删除评论和静态类。

     import android.os.Environment; public class StorageHelper { private static boolean externalStorageReadable, externalStorageWritable; public static boolean isExternalStorageReadable() { checkStorage(); return externalStorageReadable; } public static boolean isExternalStorageWritable() { checkStorage(); return externalStorageWritable; } public static boolean isExternalStorageReadableAndWritable() { checkStorage(); return externalStorageReadable && externalStorageWritable; } private static void checkStorage() { String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { externalStorageReadable = externalStorageWritable = true; } else if (state.equals(Environment.MEDIA_MOUNTED) || state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { externalStorageReadable = true; externalStorageWritable = false; } else { externalStorageReadable = externalStorageWritable = false; } } } 

    我得到它的工作,如果有人正在寻找这….这将有助于:D

     try { File dir = new File("/mnt/"); File[] dirs = dir.listFiles(); for (File _tempDIR : dirs) { String sdCard = _tempDIR.getAbsolutePath().toString(); File file = new File(sdCard + "/" + Environment.DIRECTORY_DOWNLOADS); File[] files = file.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { String _temp = files[i].getAbsoluteFile().getName() .toString();/*Your code, and what you want to find, from all the Sdcard, internal and external. Everything mounted will be found :D*/ 
     File f = new File("/mnt/sdcard/ext_sd"); if (f.exists()) { // Do Whatever you want sdcard exists } else{ Toast.makeText(MainActivity.this, "Sdcard not Exists", Toast.LENGTH_SHORT).show(); }