Skip to content

Conversation

@davidofwatkins
Copy link

@davidofwatkins davidofwatkins commented May 19, 2021

Android 10 introduced a new permissioning model called Scoped Storage for accessing files. Apps targeting Android 10 (API 29) can keep legacy permissioning until targeting Android 11 (API 30).

This doesn't affect files selected using the OS's default image/video/file pickers like Zenput's video and document fields. The gallery picker supported by this plugin, however, does need to adhere to the guidelines of Scoped Storage.

There's a lot of documentation out there about what changes need to be made. The short of it is to access files by their content URIs rather than absolute file paths. (Still, file paths may continue to work in some cases.) In the context of this plugin, that meant:

  • Referencing files with ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, <file ID>) instead of MediaStore.Images.Media.DATA
  • Loading images with BitmapFactory.decodeFileDescriptor() and getApplicationContext().getContentResolver().openFileDescriptor(<uri>) instead of just BitmapFactory.decodeFile(<absolute path>)
  • Determining a file's name with getContentResolver().query() and mime type with getContentResolver().getType(<uri>) instead of instantiating a File and guessing based on extension.

This was one of the blockers for targeting the Android 30 API level (required by Google in November), so this should relieve some headaches in the future when we make that change in Zenput.

This also adds NPM scripts for more easily publishing (draft) releases to NPM. (No CI automation yet!)

Resources on Android's Scoped Storage::

@davidofwatkins davidofwatkins requested review from ldurazo and sfcoons May 19, 2021 06:06
Copy link

@sfcoons sfcoons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me - nice work!

@davidofwatkins davidofwatkins merged commit f96682d into master May 20, 2021
@davidofwatkins davidofwatkins deleted the ZP-6167-android-scoped-storage branch May 20, 2021 17:34
spike-rob-tuvey pushed a commit to spike-barry-northern/cordova-plugin-image-picker that referenced this pull request Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants