How do I get all the memory attached to an Android device

The Android system provides the environment. Getexternalstoragedirectory () interface to get the path of memory, but the result of this interface is often not what we want. On some devices, it returns the internal storage of the mobile phone, and on some devices, it returns the external storage of the mobile phone. In addition, some Android devices support the extension of multiple sdcards. At this time, there is no way to obtain the mounting path of all memory.

How do I get the location of all memory on Android devices? Or get all the mount points

The system provides a storagemanager. It has a method called getvolumelist. The return value of this method is a storagevolume array. The storagevolume class encapsulates the mounting path, mounting status, and whether it can be removed. Unfortunately, this method is a hidden API, so we can only call this method through reflection. Here is the source code of this method.

Through reflection, all memories of Android devices are obtained.

How to judge whether the memory is built-in storage or external storage?

The storagevolume class provides an isremovable () interface, which can be called by reflection to know whether the storage can be removed. The removable memory is identified as external sdcard, and the non removable memory is identified as built-in memory.

Method isRemovable = obj.getClass().getmethod("isRemovable",new Class[0]);

How to determine the attached state of the memory?

As above, you need to reflect the system interface to get the mount status. Here is a code snippet

summary

Through the interfaces provided by the storagemanager and storagevolume class of the reflection system, you can get all the memory paths mounted on Android devices, as well as the memory type (built-in storage or external storage), as well as the mounting status of the memory.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>