capawesome-team / capacitor-plugins

⚡️ Community plugins for Capacitor. Supports Android, iOS and the Web.
https://capawesome.io/plugins/
225 stars 33 forks source link

feat: FilePicker - ask for ACCESS_MEDIA_LOCATION permission to get Exif location tags from images #293

Open Myphz opened 2 hours ago

Myphz commented 2 hours ago

Plugin(s)

Current problem

Currently, FilePicker.pickImages() does not allow developers to get location data from the exif tags. Latitude and longitude are always shown as 0, not available.

This is probably because the plugin is not asking for ACCESS_MEDIA_LOCATION permission at runtime.

Preferred solution

The plugin should maybe add a .requestPermission() method to ask for ACCESS_MEDIA_LOCATION permission at runtime. I don't know exactly how android manages permission under the hood, but I think that ACCESS_MEDIA_LOCATION is a "restricted" type of permission, thus just adding it to the AndroidManifest.xml file does not suffice, it must also be asked at runtime apparently?

I'm quite sure this is the problem because, if I give the app full access through the settings, it works correctly and it retrieves the location from the photo correctly.

Alternative options

No response

Additional context

Code to get exif tags:

const { files } = await FilePicker.pickImages();
const { data } = await Filesystem.readFile({ path: files[0].path! });
const buffer = Uint8Array.from(atob(data as string), (c) => c.charCodeAt(0)).buffer;
const tags = ExifReader.load(buffer);
console.log(tags)

I don't know if this issue is present on iOS.

Before submitting

robingenz commented 2 hours ago

Thank you for your request. I don't have time to work on the issue right now, but you are welcome to create a PR.