Device Proliferation and Application Development
One of the biggest concerns in the Android ecosystem is the proliferation of multiple variants of the Android platform. This makes it difficult for developers to write apps that work consistently across the ecosystem. Google is doing a good job in solving this fragmentation issue by providing compatibility libraries, though there are still some remaining challenges that have not been addressed completely.
One such problem which developers face is getting the access path of the real external microSD™ card. Many developers think that “Environment.getExternalStorageDirectory()” API will simply get the path of the external microSD card but it is not always the case for all the variants of Android. This can be misleading for developers, where they think it returns the real path of the external microSD card but it does not always do that.
Official Android Documentation: Note: don’t be confused by the word “external” here. This directory can better be thought as media/shared storage. It is a file system that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a file system on a computer.
Various devices from different OEMs mount the microSD card to a different path.
This is due to the potential for applications built specifically for one variant or device not being able to work with others. The convention used for the path of the microSD card varies across the Android platform and as more custom versions of the Android platform emerge, the compatibility can be weakened further. The following table shows some examples:
So the above API call doesn’t always guarantee that the path returned truly points to the real external microSD Card. It may or may not be the real path of the microSD card.
If that is the case, what is the solution?
What most people agree is that it would be very useful to have a single API which would clearly give a developer the real path of all storage devices attached, irrespective of the Android version or the manufacturer.
Application developers like the idea of more storage for their applications.
There are some ‘hacky’ or not so desirable tricks out there that the developer can implement to get the path of the microSD Card directory to work consistently across all versions of Android right from Froyo (Android 2.2) to Lollipop (Android 5.0). Many developers, however, are reluctant to implement this and therefore miss out on the ability to access extra storage available in microSD cards. Access to appropriate amounts of storage is critical for applications to function properly and avoid situations where a user runs out of available mobile memory.
Advances and innovation in microSD cards today put huge amounts of memory into very small form-factors. SanDisk’s 128 GB microSD card, for example, was released at MWC 2014 and gives the app developer an opportunity to write applications that fully utilize the available memory on the microSD card.
The possibilities are endless when application developers can utilize memory as they need and not have to starve the applications or write complicated code to reduce memory usage.
In order to help developers directly utilize various storage types in in an optimal way, SanDisk has put together all the implementations needed in a single library called “RealStoragePathLibrary”. Yes, you got it from the name. This library actually returns all the real paths of the storage devices attached to the Android phone or tablet, irrespective of the variant types of Android devices (OS version as well as manufacturer).
We are making RealStoragePathLibrary open source and available under the Apache license for application developers to download and use.
What is RealStoragePathLibrary?
- RealStoragePathLibrary is a powerful open source library with very minimal footprint. It helps to find the real paths of the storage devices attached to the Android device.
- Because it is very light-weight, the developers of Android Apps can integrate it very easily just by copying single class.
- Developers do not need to worry about the fragmentation issue in Android when they want to get the real paths of the storage devices.
- It has been tested against various versions of Android and various manufacturers.
- Android 2.3 to Android 5.0
- This library is targeted for Android Developers (Not for end users).
- As it is licensed under Apache 2.0, developers are free to use this library in their project.
- You can download this and access more information at https://github.com/SanDisk-Open-Source/RealStoragePathLibrary
- SanDisk will continue to maintain this open source project and invites developers to contribute to this and get involved in making this work as future versions and variations of Android come out.
This is a contribution by Sivaraj Velusamy, a developer working on SanDisk applications such as Memory Zone and SanDisk’s Wireless Media Drive App. Sivaraj is passionate about making it easy for Android App developers to use various types of storage.
Sivaraj is passionate about programming intuitive mobile applications that result in great user experiences.