Some Android devices treat Internal Storage as SD Cards and External Storage as EXTSD

社会主义新天地 提交于 2019-12-03 11:50:27
Environment.getExternalStorageState() returns path to internal SD mount point like "/mnt/sdcard"

Environment.getExternalStorageDirectory() refers to whatever the device manufacturer considered to be "external storage". On some devices, this is removable media, like an SD card. On some devices, this is a portion of on-device flash. Here, "external storage" means "the stuff accessible via USB Mass Storage mode when mounted on a host machine", at least for Android 2.x and above.

But the question is about external SD. How to get a path like "/mnt/sdcard/external_sd" (it may differ from device to device)?

Android has no concept of "external SD", aside from external storage, as described above.

If a device manufacturer has elected to have external storage be on-board flash and also has an SD card, you will need to contact that manufacturer to determine whether or not you can use the SD card (not guaranteed) and what the rules are for using it, such as what path to use for it.

On a rooted device, you can change your /system/etc/permissions/platform.xml to "fix" the permissions issue. The following worked for me:

  • adb pull /system/etc/permissions/platform.xml
  • Modify platform.xml such that media_rw is included in the WRITE_EXTERNAL_STORAGE permission like this:

    <permission name="android.permission.WRITE_EXTERNAL_STORAGE" >
       <group gid="sdcard_rw" />
       <group gid="media_rw" />
    </permission>
    
  • adb push platform.xml /system/etc/permissions/platform.xml

  • Restart Device

The only work around I've found so far to get write access on the device is rooting the device :(

Samsung provides a work around with a manifest entry

More details are available in the following links

http://www.xda-developers.com/android/android-3-2-code-inadvertently-preventing-write-access-to-external-storage/

and

http://www.chainfire.eu/articles/113/Is_Google_blocking_apps_writing_to_SD_cards_/

Excerpts:

It would seem that Google has a bug in their AOSP code that was introduced around Android 3.2, which affects how the OS handles USB Storage and can prevent write access to SD cards and USB sticks. XDA Elite Recognized Developer, Senior Moderator, and News Writer Chainfire sums up the issue in his blog post:

"In the past, an app would request the “WRITE_EXTERNAL_STORAGE” permission, which would grant write access to all external storages (user/group “sdcard_rw“). This has apparently been changed to only grant write access to the primary external storage. A second permission has been introduced called “WRITE_MEDIA_STORAGE“, which would grant access to the other external storages (user/group “media_rw“).

The problem is, a third party will not actually be granted this permission, only system apps and apps provided by the device manufacturer will normally be granted this permission. There are exceptions, apparently on some devices third party apps will be granted this permission, but according to the AOSP sources, they’re certainly not supposed to."

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!