在SD卡弹出后,MediaScanner在SD卡上运行?

时间:2012-09-10 08:54:04

标签: android sd-card

以下代码显示MediaScanner在弹出之后为什么在SD卡上启动了?发生了什么事?

if(intent.getDataString().equals("file:///mnt/extsd"))
        {
            if(Intent.ACTION_MEDIA_SCANNER_STARTED.equals(intent.getAction()))
            {
                //Media scanner is started
            }
            else if(Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(intent.getAction()))
            {
            }
        }

1 个答案:

答案 0 :(得分:1)

Probably this question will be helpfull关于/mnt/extsd以及如何正确使用SD卡(意为Environment.getExternalStorageDirectory())。您还必须检查SD卡状态。我的意思是:

boolean isExternalStorageWriteable = false, isExternalStorageReadable = false;
// Check SD Card for Read/Write
if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    isExternalStorageWriteable = true;
    isExternalStorageReadable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
    isExternalStorageReadable = true;
} 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
}