简体   繁体   中英

How to detect if an sdcard or mount point will mount as removable storage or MTP?

当android手机通过USB电缆连接到计算机时,它可能会作为可移动存储安装,但某些手机可能会将其作为mtp(媒体传输协议)安装,是否有一种方法可以在android中检测到sdcard是否将其安装为可移动或mtp ?

You can use

Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); 

to see if the external storage is mounted and you can use

Environment.getExternalStorageState().equals(Environment.MEDIA_REMOVED);

to see if it is removed completely. You will find all the different cases you need in the Environment class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM