Android 判断是不是有外置SD卡

2024-12-22 13:01:33
推荐回答(1个)
回答1:

/**
* 判断是否存在SD卡
*
* @return
*/
public static final boolean hasSDCard() {

return Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
}

public static final String getCachePath(Context context) {
if (hasSDCard()) {
return Environment.getExternalStorageDirectory().toString() + File.separator + CACHE_ROOT_DIRECTORY;
} else {
return context.getCacheDir() + File.separator + CACHE_ROOT_DIRECTORY;
}
}