我们如何区分闪存和SD卡内存之间?闪存、内存、SD

2023-09-08 10:04:35 作者:乄刚强ご

一些Android设备有内置闪存,我们可以检查这个内存 Environment.getExternalStorageDirectory()。但是,当我们插入SD卡,则系统区分这两个与 /存储/ sdcard0 /存储/ sdcard1

Some android devices has built-in flash memory, and we can check this memory at Environment.getExternalStorageDirectory(). But, when we insert an SD card, then the system differentiates these two with /storage/sdcard0 and /storage/sdcard1.

我不知道是否 /存储/ sdcard0 是闪存或SD卡存储。任何人都可以提供任何解释,哪个是哪个?

I am not sure whether /storage/sdcard0 is flash memory or SD card memory. Could anyone provide any explanation as to which is which?

推荐答案

使用方法 Environment.isExternalStorageRemovable()来确定它是否是一个可移动的SD卡或没有。

Use the method Environment.isExternalStorageRemovable() to determine if it's a removable SD card or not.

编辑澄清:

考虑以下方法:

public enum ExternalStorageStatus { 
    READ_WRITE , READ_ONLY, NONE
}

public static ExternalStorageStatus checkExternalStorageStateAvailable(){
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return ExternalStorageStatus.READ_WRITE;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return ExternalStorageStatus.READ_ONLY;
    } else {
        return ExternalStorageStatus.NONE;
    }
}

方法 Environment.getExternalStorageState()返回存储的当前状态。如果没有真正的外部存储(即介质中 isExternalStorageRemoveable() ==假),那么这将返回内部存储的当前状态。如果 isExternalStorageRemoveable() == true,则getExternalStorageState()返回可移动SD卡的状态。

The method Environment.getExternalStorageState() returns the current state of your storage. If no REAL external storage (i.e. a medium in which isExternalStorageRemoveable() == false), then this returns the current state of your internal storage. If isExternalStorageRemoveable() == true, then getExternalStorageState() returns the state of your removable SD card.

实际外部存储的优先次序。

Actual external storage is prioritized.

 
精彩推荐
图片推荐