android 2.3 取内外置SD卡

阅读更多
在android2.3中

判断内置SD卡是否挂载:

if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))

{

//为true的话,内置sd卡存在

}

判断外置SD卡是否挂载:

if(Environment.getStorageState(Environment.STORAGE_PATH_SD2).equals(Environment.MEDIA_MOUNTED))
{

//为true的话,外置sd卡存在

}



顺带描述怎么取得sdcard的空间大小,

        File sdcardDir = Environment.getExternalStorageDirectory();
        StatFs sf = new StatFs(sdcardDir.getPath()); //sdcardDir.getPath())值为/mnt/sdcard,想取外置sd卡大小的话,直接代入/mnt/sdcard2
        long blockSize = sf.getBlockSize(); //总大小
        long blockCount = sf.getBlockCount();
        long availCount = sf.getAvailableBlocks(); //有效大小

你可能感兴趣的:(Environment,SD)