I am developing an app that needs direct access to the root folder of the sdcard, however it seems in Android 4.2, the standard /sdcard directory now points to an "emulated" sdcard specific to the user running the app. This is not good, as my app requires access to a file that is stored on the top level of the sdcard. Does anyone know how to directly access the sdcard in Android 4.2?
Perhaps I am misunderstanding your question, however, with my Nexus Galaxy running Android 4.2.1 I can access my sd card using Environment.getExternalStorageDirectory(). The returned directory is /storage/emulated/0, but the content is that of /sdcard.
Can you use the storage directory as a File type? (java.io.File)
If so, you can get the external storage (Typically SD card, but will be main storage on phones with no SD card) by using code such as this in your method:
File path = Environment.getExternalStorageDirectory();
Additionally, access of storage requires READ_EXTERNAL_STORAGE permission in your Android Manifest - with WRITE_EXTERNAL_STORAGE being needed if any data is modified. Here are these permissions as they would appear in the manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Sources:
http://developer.android.com/reference/android/os/Environment.html http://developer.android.com/reference/android/Manifest.permission.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With