现在的位置: 首页 > 综合 > 正文

android 判断 sdcard 是否是 emulated

2018年04月19日 ⁄ 综合 ⁄ 共 672字 ⁄ 字号 评论关闭

最近遇到了无法通过 pm 命令使用系统的安装器把 apk 安装到 sdcard 的问题,返回 

Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]

主要原因是 emulated sdcard 不能安装 apk,因此在安装之前需要判断 sdcard 是否是 emulated。
这个功能系统已经提供了api,Environment.isExternalStorageEmulated();

Returns whether the device has an external storage device which is emulated. If true, the device does not have real external storage, and the directory returned by
getExternalStorageDirectory() will be allocated using a portion of the internal storage system.

Certain system services, such as the package manager, use this to determine where to install an application.

Emulated external storage may also be encrypted - see android.app.admin.DevicePolicyManager.setStorageEncryption(android.content.ComponentName, boolean) for additional details.

抱歉!评论已关闭.