xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 505 forks source link

[Bug] Still unable to use MediaPicker ImageCapture on Android without declaring WRITE_EXTERNAL_STORAGE permissions in manifest #2037

Closed plebnz closed 1 year ago

plebnz commented 2 years ago

Description

Found in Xamarin Essentials 1.7.3 on Android 11 targeting SDK v31

MediaPicker Image Capture still requires WRITE_EXTERNAL_STORAGE in the manifest otherwise i get a "You need to declare using the permission: android.permission.WRITE_EXTERNAL_STORAGE in your AndroidManifest.xml"

All I want is to capture an image and post it to a server without writing to external storage - Why cant we have the option to write/cache to directories that do not require this permission?

Update: For now I have forked this project and deleted line 59 from the MediaPicker.android file in the project. await Permissions.EnsureGrantedAsync(); <-- Deleted

I have compiled the forked project and added it to my application and I can now take pictures and post to server using app cache and no reqauirement to add WRITE_EXTERNAL_STORAGE to manifest.

I feel that i missing something here, some questions I have

I dont think the docs are very clear around how this should be handling it and I'm pretty sure I have misunderstood something and I'm just not using the official package correctly in my application correctly so happy to be corrected and delete this bug report as required.

plebnz commented 2 years ago

Looks like could be sorted at same time https://github.com/xamarin/Essentials/issues/2041

avii-7 commented 1 year ago

Can you please mention the steps of compiling and adding the modified project.

plebnz commented 1 year ago

@avii-7

I created a fork which can be found here - though it might be out of date now https://github.com/plebnz/Essentials

You can either clone the latest offical or use mine. If you use the official solution, and it has not yet been fixed, you'll need to delete or remove the line as mentioned in the issue description. The fork already has this done.

  1. Once you have a local copy with the line removed/commented, you can perform a release build to output the DLL libraries.
  2. Copy the locally built xamarin essential dll to you xamarin project. I created a lib directory and placed it in there.
  3. Remove the official xamarin essentials nuget package from the project
  4. Add a reference to the imported DLL to replace the official package with the locally built dll

Boom, you should now be up and running.

samir05051994 commented 1 year ago

hi @jamesmontemagno @jfversluis The CapturePhotoAsync is not working in android 13 error is "You don't have Storage Write Permission"

I think this bug is due to the CapturePhotoAsync method still having Storage write permission checking please help us to fix this

image
samir05051994 commented 1 year ago

hi Gerald

Thanks a lot for this fix

Regards Samir

On Thu, Jan 26, 2023 at 4:50 PM Gerald Versluis @.***> wrote:

Closed #2037 https://github.com/xamarin/Essentials/issues/2037 as completed via #2073 https://github.com/xamarin/Essentials/pull/2073.

— Reply to this email directly, view it on GitHub https://github.com/xamarin/Essentials/issues/2037#event-8361980431, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE2XOSBQRUXRZ5XEZDTJYS3WUI3FDANCNFSM57BQW72Q . You are receiving this because you commented.Message ID: @.***>

plebnz commented 1 year ago

When will this fix be available via the nuget packages?

suhas100 commented 1 year ago

@jamesmontemagno it is getting crashing on Android 13 Please suggest any work around its very crucial