display.captureScreen(true) fails on Android 13+

This has stopped working on Android 13+ due to the changes in how permissions are scoped (I think) - unless the permission was already granted and the user upgraded to Android 13, then this works as expected.

No error, it just logs that it is unable to save and silently fails.

On previous Android versions this works fine, a permission is spawned if required. but this no longer happens on Android 13+.

Anyone got this working?

I’ll recap some of what we discussed and a couple details turned up by some further digging.

This StackOverflow post basically suggests you can omit it, if you’re running a certain API (I guess 33, although slightly earlier is when deprecation began?), which you can check against the version number.

There is a canWriteToExternalStorage method in the activity code, but it seems to be unused.

The Android-specific AddBitmapToPhotoLibrary() code ultimately goes through this logic. I’ll look around a bit more, but I suspect that check could be done here, and just set the state to GRANTED.

It looks like network.download() might also have issues, probably with a similar fix.


On the read side of things it looks like media.selectNewVideo() needs some addressing too.

1 Like

There seem to be new permissions since API 33 for reading media images, audio and videos:

It might also be that now you’ll need to explicitly request permissions during runtime.

You could check if you have the "WRITE_EXTERNAL_STORAGE" permission via system.getInfo( "androidGrantedAppPermissions") and if you don’t, then you should be able to request it via native.showPopup( "requestAppPermission", { appPermission="android.permission.WRITE_EXTERNAL_STORAGE" } ).

1 Like

WRITE_EXTERNAL_STORAGE and WRITE_MEDIA_IMAGES are in manifest but is ignored once compiled.

Seems like WRITE_MEDIA_IMAGES is ignored (or maybe READ is a higher level than WRITE?)

Querying the apk show this

Requesting permissions does nothing (as in there is no popup displayed). I’ve already tried WRITE_EXTERNAL_STORAGE, WRITE_MEDIA_IMAGES and READ_MEDIA_IMAGES.
This is displayed in console PermissionServices.ApiLevel23.requestPermissions(): All permissions that were requested have already been granted!

Still the same result WARNING: display.captureScreen() unable to capture screen

Would something like this be a simple fix?

PermissionState writeExternalStoragePermissionState = permissionsServices.getPermissionStateFor(PermissionsServices.Permission.WRITE_EXTERNAL_STORAGE) || permissionsServices.getPermissionStateFor(PermissionsServices.Permission.WRITE_MEDIA_IMAGES)

Did you ever manage to get this working? Or are you still waiting for a fix?

Having the same problem currently with one of my apps, but whatever I try it will not work on a device with android 13+

I’m interested in a solution to this, too.

1 Like

I did have a go at it (should have the code somewhere), but was just sending someone builds rather than grinding through tests on an emulator or device, and we didn’t have any luck during that limited window. I’m sure it must be close, and don’t think it would be too hard to actually do right, but it’s been very out-of-sight, out-of-mind. :slight_smile:

Great, this is an opportunity to talk about it … I’m using display.captureBounds()-which is very similar to screenCapture- to save a portion of the screen to the library and doesn’t work either in my phone with Android 14 (SDK 34).

Some of my apps are being affected by this behaviour.