WebsiteBeaver / android-document-scanner

66 stars 48 forks source link

Reviewed fixes for android devices above version 10, needs to be test… #32

Closed shahawi closed 1 year ago

shahawi commented 1 year ago

…ed for older devices

Reviewed fixes for android devices above version 10, needs to be tested for older devices

Needs review, The main change was using URI instead of filepath and using Mediastore for file storage

shahawi commented 1 year ago

As a note it does not work with older devices Probably minimum sdk supported is 29, The problem is that someone needs to modify several files to handle both scenarios at the same time.

Using sdk 29 will target 78.5% of android devices, I think according to the latest numbers.

shahawi commented 1 year ago

Also you will need to create a filepaths.xml in the top app folder under res/xml and add this to your app manifest <uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-permission android:name="android.permission.CAMERA" />

<provider android:name="androidx.core.content.FileProvider" android:authorities="com.Me.MyApp.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider>

shahawi commented 1 year ago

this is file_paths.xml

`

`

dmarcs commented 1 year ago

Thanks for the pull request. I don't like how this saves images to the user's photo gallery, and creates a folder called MyAPP for those images. I wonder what exactly in this pull request fixed the issue for you. Was it reading the bitmap without OpenCV, or was it using MediaStore?

I think the way I want to solve this bug is to add more useful error messages. I'll add checks to see if the image gets saves, and if the image is readable.

I wonder if the cause of the issue is that you don't have permission to save/read images. If that's the case I would rather not make all of these changes, and would like to figure out how to get the correct permissions on the device you're using.

shahawi commented 1 year ago

The fix is simply due to restrictions starting from android 11 that is caused by the concept of scoped storage https://developer.android.com/about/versions/11/privacy/storage

Now you don't have permission to access external storage, Instead you can use a folder associated with your app inside the external storage in this case the pictures directory and then calling the subfolder the name associated withyour app

This folder is accessed through mediastore only

The correct permissions are given I even checked it through the app info in my device

Hope this helps.

dmarcs commented 1 year ago

I was able to get the current code to work on Android 13 without these changes, so it might not be a permissions issue. I use BitmapFactory in https://github.com/WebsiteBeaver/android-document-scanner/pull/33 if OpenCV fails to read the image.