Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android getExternalStorageState()返回在具有可用内存的HTC上删除的媒体_Android - Fatal编程技术网

Android getExternalStorageState()返回在具有可用内存的HTC上删除的媒体

Android getExternalStorageState()返回在具有可用内存的HTC上删除的媒体,android,Android,在我的应用程序中,我试图检查用户是否已将手机作为驱动器连接到pc,这样我就可以警告他们断开连接,因为我需要访问存储 它在我测试过的所有4-5设备上都能正常工作,除了这款HTC Desire X手机、安卓4.0.4。它没有SD卡,但有大约2GB的存储空间可供写入 这是我使用的代码 private void checkStorage() { // Get the external storage's state String state = Environment.getExtern

在我的应用程序中,我试图检查用户是否已将手机作为驱动器连接到pc,这样我就可以警告他们断开连接,因为我需要访问存储

它在我测试过的所有4-5设备上都能正常工作,除了这款HTC Desire X手机、安卓4.0.4。它没有SD卡,但有大约2GB的存储空间可供写入

这是我使用的代码

private void checkStorage() {
    // Get the external storage's state
    String state = Environment.getExternalStorageState();
    Log.d("STATE", state);
    if (state.equals(Environment.MEDIA_MOUNTED)) {
        // Storage is available and writeable
        externalStorageAvailable = externalStorageWriteable = true;
    } else if (state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        // Storage is only readable
        externalStorageAvailable = true;
        externalStorageWriteable = false;
    } else {
        // Storage is neither readable nor writeable
        externalStorageAvailable = externalStorageWriteable = false;
    }
}
因此,当我运行它时,logcat调试标记返回:

removed
根据文件:

http://developer.android.com/reference/android/os/Environment.html#MEDIA_REMOVED

"Storage state if the media is not present."
如何修改此代码,使其检测是否存在可供使用的内存

现在,还有一件事。在这部手机上,当我尝试从浏览器下载图像时,不允许Im,我收到以下消息:

No SD card
An SD card is required to download <filename>
OK

您如何知道有2GB可用?哪里有?听起来这个设备好像没有外部存储器,而这个存储器当前可用于应用程序。当我打开ES File explorer时,mnt/文件夹中有一些文件夹,例如DCIM,相机在其中存储图像,下载文件夹中有一个蓝牙文件夹,其中包含一些歌曲。是否可以在这样的设备上运行需要某种存储的应用程序?是否尝试重新启动设备?是的,我尝试过:)是否尝试过:Boolean isSDPresent=android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
File directory = null;
    File file = null;

    try {
        directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), 
                Utils.getWritableDiectory(Locale.ENGLISH));

        if (!directory.exists()) {
            directory.mkdirs();
        }

            file = new File(directory, "data.json");