flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

Add support for granular media permissions on Android 13

Open felipheallef opened this issue 1 year ago • 16 comments

:sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Feature: Added support for the new Android 13 granular media permissions: READ_MEDIA_IMAGES, READ_MEDIA_VIDEO and READ_MEDIA_AUDIO.

:arrow_heading_down: What is the current behavior?

Apps should ask for READ_EXTERNAL_STORAGE to read data from the external storage.

:new: What is the new behavior (if this is a feature change)?

Apps targeting Android 13 must request one or more new permissions instead of the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions.

If the user previously granted your app the READ_EXTERNAL_STORAGE permission, the system automatically grants each of the new permissions to the app.

:boom: Does this PR introduce a breaking change?

No, everything should work as expected.

:bug: Recommendations for testing

Run the example project at permission_handler/example using an emulator or physical device running Android 13.

:memo: Links to relevant issues/docs

:thinking: Checklist before submitting

  • [x] I made sure all projects build.
  • [x] I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • [x] I updated CHANGELOG.md to add a description of the change.
  • [x] I followed the style guide lines (code style guide).
  • [x] I updated the relevant documentation.
  • [x] I rebased onto current master.

felipheallef avatar Jul 12 '22 16:07 felipheallef

any timeline when these changes might be released?

TatsuUkraine avatar Aug 19 '22 12:08 TatsuUkraine

Android 13 started to rollout, we still have no ability to use these READ_MEDIA_IMAGES, READ_MEDIA_VIDEO and READ_MEDIA_AUDIO Who can answer when this change will be released?

eherbut avatar Aug 22 '22 14:08 eherbut

Any plans to release this? Android 13 is already out

armandojimenez avatar Aug 30 '22 01:08 armandojimenez

This PR needs to be approved and merged by a maintainer in order to be released, so I don't have any idea when these changes will be released.

felipheallef avatar Aug 30 '22 12:08 felipheallef

Until this get merged you can use compileSdk 32 and targetSdk 32 and it will work just fine. I hope this gets merged soon so we could use API 33, but it is what it is for now.

MilosKarakas avatar Sep 02 '22 11:09 MilosKarakas

Hi! Does this work on Android 12 or lower? Do I need to separately handle permission to request full media (all photos, videos & audio) separately inside code?

Thanks.

alexmercerind avatar Sep 05 '22 17:09 alexmercerind

Android 13 introduces the granular permissions. Android 12 and lower does not have that and everything should work the same as is used to.

MilosKarakas avatar Sep 05 '22 19:09 MilosKarakas

Android 13 introduces the granular permissions. Android 12 and lower does not have that and everything should work the same as is used to.

Yes, but now do we have to check if Android < 12 keep asking for storage permission and if Android > 12 ask for media or pictures permissions? Or just ask for a granular one on Android 13 and it should fallback to storage permission if it's a lower android version?

armandojimenez avatar Sep 05 '22 19:09 armandojimenez

@armandojimenez

I tried using only READ_MEDIA_AUDIO (i.e. only audio, video or images) on Android 12, it turns out it does nothing.

I see this on my terminal (using Permission.storage.audio):

no permissions found in manifest for: []32

I still needed to use existing Permission.storage.request on Android 12. Likely READ_MEDIA_XYZ is only Android 13 specific. Maybe querying Android version is only option & using Permission.storage & Permission.audio based on that. package:device_info_plus or MethodChannel impl. within project can be used for this purpose I guess.


  • I did upgrade my targetSdkVersion & compileSdkVersion to 33.
  • Added READ_MEDIA_AUDIO to my AndroidManifest.xml.

Android is not my field expertise, deprecated methods everywhere after every release. More & more permissions with each SDK.

Still, It would've been cooler if Android engineers could handle it automatically. i.e. showing full-media access dialog on Android 12 or lower.

alexmercerind avatar Sep 05 '22 20:09 alexmercerind

Anyone knows how can I use this branch in my app?

armandojimenez avatar Sep 05 '22 20:09 armandojimenez

@armandojimenez

I tried using only READ_MEDIA_AUDIO (i.e. only audio, video or images) on Android 12, it turns out it does nothing.

I see this on my terminal (using Permission.storage.audio):

no permissions found in manifest for: []32

I still needed to use existing Permission.storage.request on Android 12. Likely READ_MEDIA_XYZ is only Android 13 specific. Maybe querying Android version is only option & using Permission.storage & Permission.audio based on that. package:device_info_plus or MethodChannel impl. within project can be used for this purpose I guess.

  • I did upgrade my targetSdkVersion & compileSdkVersion to 33.
  • Added READ_MEDIA_AUDIO to my AndroidManifest.xml.

Android is not my field expertise, deprecated methods everywhere after every release. More & more permissions with each SDK.

Still, It would've been cooler if Android engineers could handle it automatically. i.e. showing full-media access dialog on Android 12 or lower.

This is what I will test now. I created a method channel that returns me the SDK Int, and will add new logic only if Android > 12

armandojimenez avatar Sep 05 '22 20:09 armandojimenez

Tried like this:

permission_handler: 
    git:
      url: https://github.com/felipheallef/flutter-permission-handler
      path: permission_handler 

But I am getting this error with pub get:

Because every version of permission_handler from git depends on permission_handler_platform_interface ^3.8.0 which doesn't match any versions, permission_handler from git is forbidden.
So, because believe depends on permission_handler from git, version solving failed.
pub get failed (1; So, because believe depends on permission_handler from git, version solving failed.)

armandojimenez avatar Sep 05 '22 21:09 armandojimenez

Hi! Does this work on Android 12 or lower? Do I need to separately handle permission to request full media (all photos, videos & audio) separately inside code?

Thanks.

Yes, it does work on Android < 13 but you still need to set targetSdkVersion 33. Also I'd recommend you to use device_info_plus to check if Android SDK version is 33 or higher and then ask this permissions.

felipheallef avatar Sep 05 '22 22:09 felipheallef

Tried like this:

permission_handler: 
    git:
      url: https://github.com/felipheallef/flutter-permission-handler
      path: permission_handler 

But I am getting this error with pub get:

Because every version of permission_handler from git depends on permission_handler_platform_interface ^3.8.0 which doesn't match any versions, permission_handler from git is forbidden.
So, because believe depends on permission_handler from git, version solving failed.
pub get failed (1; So, because believe depends on permission_handler from git, version solving failed.)

@armandojimenez this happens because I have increased the version number for the packages in this PR. But I can publish these changes into a new package on pub.dev if you want to use these features.

felipheallef avatar Sep 05 '22 23:09 felipheallef

Tried like this:

permission_handler: 
    git:
      url: https://github.com/felipheallef/flutter-permission-handler
      path: permission_handler 

But I am getting this error with pub get:

Because every version of permission_handler from git depends on permission_handler_platform_interface ^3.8.0 which doesn't match any versions, permission_handler from git is forbidden.
So, because believe depends on permission_handler from git, version solving failed.
pub get failed (1; So, because believe depends on permission_handler from git, version solving failed.)

@armandojimenez this happens because I have increased the version number for the packages in this PR. But I can publish these changes into a new package on pub.dev if you want to use these features.

Please do! I had to fork your branch, then edit the interface package version number to 3.7.0 so it does not throw errors, and then I had to do overrides like this:

dependency_overrides:
  permission_handler_android: 
    git:
      url: https://github.com/armandojimenez/flutter-permission-handler
      path: permission_handler_android  

  permission_handler_platform_interface: 
    git:
      url: https://github.com/armandojimenez/flutter-permission-handler
      path: permission_handler_platform_interface

I just tested this and everything is working! But I had to create a method channel that returns the SDK int and do a condition to ask for Permission.photo when > Android12, and Permission.storage when < Android12. It would be good if the logic in the package verified the SDK version, and fallback to Permission.storage, so we don't need to handle that logic on the dart side

armandojimenez avatar Sep 05 '22 23:09 armandojimenez

All checks have failed. You should be improve these problems.

jack24254029 avatar Sep 20 '22 05:09 jack24254029

With this pull I was able to release my app with SDK 33. Since this was closed, any plans to implement this permissions?

armandojimenez avatar Sep 22 '22 15:09 armandojimenez

@felipheallef why was this closed?

Zazo032 avatar Oct 03 '22 12:10 Zazo032

@Zazo032 @armandojimenez It appears because PR #934 supersedes it.

MatthewPatience avatar Oct 18 '22 02:10 MatthewPatience