0

I have an app that shows pictures via ShareIntent. I have the correct code asking for storage permissions:

if (Build.VERSION.SDK_INT >= 23) {
    if (getActivity().checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
        doThing()
    } else {
        ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
        Toast.makeText(getActivity(), R.string.permission, Toast.LENGTH_LONG).show();
    }
} else {
    doThing()
}

A user reported that he on Android Marshmellow he can use my app for photos from the storage (so like phone storage, external storage), but it doesn't work when he shares from SD card (removable storage). Why could this be? I have also heard that accessing the SD card needs a special prompt (and have seen it in other apps), but why is that and how to do it?

Pankaj Lilan
  • 4,245
  • 1
  • 29
  • 48
JoeDoe
  • 1
  • 3
  • What do you mean by external storage? Do you mean Internal Built-in ROM? – Ümañg ßürmån Oct 25 '18 at 06:27
  • @UmangBurman I think external storage is defined us the on-device storage of the phone. As opposed to internal storage, the app-only storage section. – JoeDoe Oct 25 '18 at 06:31
  • Oh, Okay, well you are right about "a special prompt" ... To access SD Card on 6.0+ devices you need a special prompt and that prompt is called as "Document Tree" – Ümañg ßürmån Oct 25 '18 at 06:35
  • @UmangBurman I see. Any idea why that's the case? And could you point me to some documentation? – JoeDoe Oct 25 '18 at 06:40
  • There is no proper docs that I could find, but, here is an example: [SO Example](https://stackoverflow.com/questions/36862675/android-sd-card-write-permission-using-saf-storage-access-framework) – Ümañg ßürmån Oct 25 '18 at 06:51
  • @UmangBurman Alright, thanks! Now any idea how I can test using it? Neither my phone, nor the Android API 28 and 23 emulator show this behaviour. – JoeDoe Oct 25 '18 at 07:03
  • I've used it in one of my apps, You need to make a Custom dialog as shown in the example link and then you must be having a SD Card inserted. So that it will detect and show that Dialog and then from Document Tree you need to select your SD card. – Ümañg ßürmån Oct 25 '18 at 07:13
  • @UmangBurman Yes, but how do I know if it worked? The issue doesn't happen with any of my devices. Is there any emulator that has this issue too? My phone does have an SD card, but not this problem. – JoeDoe Oct 25 '18 at 07:15
  • Actually I'm in office right now and I don't have the source code in this Mac, I would upload my source of the project and give you the link of my repo and you can find out how it works. What API is your Phone functioning on anyway? – Ümañg ßürmån Oct 25 '18 at 07:21
  • @UmangBurman That would be great! It's on Oreo 8.0.0. Maybe it's a samsung thing that it doesn't request those. Or I messed something up in my developer settings? Also, on my emulator other apps request it, but my app works fine without it. It's quite weird. – JoeDoe Oct 25 '18 at 07:26
  • Haha, Yeah may be so.. Do you have ES File Explorer installed on your device? – Ümañg ßürmån Oct 25 '18 at 07:28
  • @UmangBurman Nope, I'm using Mixplorer and Solid explorer. Edit: I just tested, and other apps do request this on my phone. But I can't get my app not to work without it. – JoeDoe Oct 25 '18 at 07:29
  • I think your app needs the above implementation as well to request permission for SD Card. Weird behavior as you said earlier. – Ümañg ßürmån Oct 25 '18 at 07:41

0 Answers0