Camera (navigator.camera.getPicture) not working on Android but works on IOS

Hi,
My app upload pictures using the camera or album.
It is working fine when I build it for IOS but it does not work when I build it for Android.
It seems to bem permission issue but I could not resolve it.
Does anyone may help me?

<?xml version='1.0' encoding='utf-8'?>
<widget id="br.com.harcan" version="0.0.67" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
    <name>Odonto Scan</name>
    <description>
        Descrição
    </description>
    <author email="bonates@harpia.com.br" href="http://harpia.com.br">
        Harpia
    </author>
    <content src="index.html" />
    <preference name="phonegap-version" value="cli-9.0.0" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="22" />
    <preference name="android-targetSdkVersion" value="30" />
		
    <icon src="resources/icon/odontoscan-150.png" />
    <platform name="android">
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
        <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
        <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
		<!--<custom-preference name="android-manifest/uses-permission/@android:name" value="android.permission.FOREGROUND_SERVICE" />
		<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
		<application android:usesCleartextTraffic="true" />
		</edit-config>-->
		
		<!--<config-file target="AndroidManifest.xml" parent="/*" mode="merge">
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-feature android:name="android.hardware.camera" />
        <uses-feature android:name="android.hardware.camera.autofocus" />
        </config-file>-->
    </platform>

    <platform name="ios">
        <icon height="57" src="resources/ios/icon/icon.png" width="57" />
        <icon height="114" src="resources/ios/icon/icon@2x.png" width="114" />
        <icon height="20" src="resources/ios/icon/icon-20.png" width="20" />
        <icon height="40" src="resources/ios/icon/icon-20@2x.png" width="40" />
        <icon height="60" src="resources/ios/icon/icon-20@3x.png" width="60" />
        <icon height="29" src="resources/ios/icon/icon-29.png" width="29" />
        <icon height="58" src="resources/ios/icon/icon-29@2x.png" width="58" />
        <icon height="87" src="resources/ios/icon/icon-29@3x.png" width="87" />
        <icon height="48" src="resources/ios/icon/icon-24@2x.png" width="48" />
        <icon height="55" src="resources/ios/icon/icon-27.5@2x.png" width="55" />
        <icon height="88" src="resources/ios/icon/icon-44@2x.png" width="88" />
        <icon height="172" src="resources/ios/icon/icon-86@2x.png" width="172" />
        <icon height="196" src="resources/ios/icon/icon-98@2x.png" width="196" />
        <icon height="216" src="resources/ios/icon/icon-108@2x.png" width="216" />
        <icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
        <icon height="80" src="resources/ios/icon/icon-40@2x.png" width="80" />
        <icon height="120" src="resources/ios/icon/icon-40@3x.png" width="120" />
        <icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
        <icon height="100" src="resources/ios/icon/icon-50@2x.png" width="100" />
        <icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
        <icon height="120" src="resources/ios/icon/icon-60@2x.png" width="120" />
        <icon height="180" src="resources/ios/icon/icon-60@3x.png" width="180" />
        <icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
        <icon height="144" src="resources/ios/icon/icon-72@2x.png" width="144" />
        <icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
        <icon height="152" src="resources/ios/icon/icon-76@2x.png" width="152" />
        <icon height="167" src="resources/ios/icon/icon-83.5@2x.png" width="167" />
        <icon height="1024" src="resources/ios/icon/icon-1024.png" width="1024" />
        <splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
        <splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
        <splash height="2688" src="resources/ios/splash/Default-2688h~iphone.png" width="1242" />
        <splash height="1242" src="resources/ios/splash/Default-Landscape-2688h~iphone.png" width="2688" />
        <splash height="1792" src="resources/ios/splash/Default-1792h~iphone.png" width="828" />
        <splash height="828" src="resources/ios/splash/Default-Landscape-1792h~iphone.png" width="1792" />
        <splash height="2436" src="resources/ios/splash/Default-2436h.png" width="1125" />
        <splash height="1125" src="resources/ios/splash/Default-Landscape-2436h.png" width="2436" />
        <splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
        <splash height="1242" src="resources/ios/splash/Default-Landscape-736h.png" width="2208" />
        <splash height="1536" src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" />
        <splash height="2048" src="resources/ios/splash/Default-Landscape@~ipadpro.png" width="2732" />
        <splash height="768" src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" />
        <splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
        <splash height="2732" src="resources/ios/splash/Default-Portrait@~ipadpro.png" width="2048" />
        <splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768" />
        <splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640" />
        <splash height="480" src="resources/ios/splash/Default~iphone.png" width="320" />
        <splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
    </platform>
	
    <access origin="*" />
    <allow-navigation href="*" />
	<allow-navigation href="file:*" />
	<allow-navigation href="data:*" />
    <allow-intent href="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
	

    <platform name="android">
		<feature name="http://api.phonegap.com/1.0/file" />
		<feature name="File">
			   <param name="android-package" value="org.apache.cordova.file.FileUtils" />
		</feature>
		<feature name="FileTransfer">
			  <param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
		</feature>
		<feature name="Storage">
			   <param value="org.apache.cordova.Storage" name="android-package"/>
		</feature>
		<feature name="http://api.phonegap.com/1.0/network"/>

        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
		<preference name="SplashScreenDelay" value="2000" />
		<preference name="AutoHideSplashScreen" value="true" />	
		<preference name="permissions" value="none" />		
		<preference name="WKWebViewOnly" value="true" />
		<feature name="CDVWKWebViewEngine">
			<param name="ios-package" value="CDVWKWebViewEngine" />
		</feature>
		<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />

        <config-file parent="NSCameraUsageDescription" target="*-Info.plist">
            <string>Este aplicativo precisa do acesso a camera!</string>
        </config-file>
        <feature name="File">
            <param name="ios-package" value="CDVFile" />
        </feature>
        <feature name="FileTransfer">
            <param name="ios-package" value="CDVFileTransfer" />
        </feature>
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
	
    <engine name="android" spec="9.0.0" />
    <plugin name="cordova-plugin-statusbar" />
    <preference name="StatusBarOverlaysWebView" value="false" />
    <preference name="StatusBarBackgroundColor" value="#00537f" />
    <preference name="StatusBarStyle" value="lightcontent" />
    <plugin name="cordova-plugin-cleartext" />
	<plugin name="cordova-plugin-wkwebview-file-xhr" version="~3.0.0" />
    <plugin name="cordova-plugin-camera"/>
    <plugin name="cordova-plugin-device"/>
    <plugin name="cordova-plugin-device-motion"/>
    <plugin name="cordova-plugin-device-orientation"/>
    <plugin name="cordova-plugin-file"/>
    <plugin name="cordova-plugin-geolocation"/>
    <plugin name="cordova-plugin-globalization"/>
    <plugin name="cordova-plugin-inappbrowser"/>
    <plugin name="cordova-plugin-network-information"/>
    <plugin name="cordova-plugin-splashscreen"/>
    <plugin name="cordova-plugin-whitelist"/>
    <plugin name="cordova-plugin-settings-hook"/>
    <plugin name="cordova-plugin-media-capture"/>
    <plugin name="cordova-plugin-dialogs"/>
    <plugin name="cordova-plugin-vibration"/>
    <plugin name="cordova-plugin-wkwebview-engine"/>
	<plugin name="@ahovakimyan/cordova-plugin-wkwebviewxhrfix"/>
	<plugin name="cordova-plugin-android-permissions" />
	
	<!--
	<plugin name="cordova.plugins.diagnostic" /> 
	<preference name="AndroidXEnabled" value="true" />
	<plugin name="cordova-plugin-androidx-adapter" />
	<preference name="AndroidXEnabled" value="true" />
	<plugin name="@havesource/cordova-plugin-push" spec="2.0.0" />
	<platform name="android">
		<resource-file src="google-services.json" target="/app/google-services.json" />
	</platform>

    <plugin name="cordova-plugin-file-opener2"/>
    <plugin name="cordova-plugin-media" />
	-->
	
    <!-- 
    <plugin name="cordova-plugin-file-transfer" source="npm" spec="~1.5.0" />
    <plugin name="cordova-plugin-themeablebrowser" source="npm" spec="~0.2.17" />
	-->
</widget>

Tip : If you’re pasting code, html or config files, surround the code with triple back ticks (```), before the first line and after the last one. It will be formatted properly. (We fixed it for you this time)

Are you getting any error messages?

No, no error messages.

/data/user/0/br.com.harscan/cache/IMG_20211207_100641444.jpg?1638969242026:1 GET file:///data/user/0/br.com.harscan/cache/IMG_20211207_100641444.jpg?1638969242026 net::ERR_ACCESS_DENIED

/data/user/0/br.com.harscan/cache/IMG_20211207_100641444.jpg?1638969242026:1 GET file:///data/user/0/br.com.harscan/cache/IMG_20211207_100641444.jpg?1638969242026 net::ERR_ACCESS_DENIED

Where do you see these messages?

Chrome Remote Debugger.

Could be a CORS issue - you may need to add a Content-Security-Policy.

I have tried a lot of configurations but none of them fix it…

    <meta http-equiv="Content-Security-Policy" content="img-src 'self' data:; default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'" />		
    <!--<meta http-equiv="Content-Security-Policy" content="img-src 'self' data:; default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; media-src *; default-src 'self' data: gap: cdvfile: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *" />-->
    <!--<meta http-equiv="Content-Security-Policy" content="img-src 'self' data:; default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; default-src 'self' data: gap: cdvfile: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *" />-->
    <!--<meta http-equiv="Content-Security-Policy" content="img-src 'self' data:; default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; default-src 'self' data: gap: ms-appdata: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *" />-->
    <!--<meta http-equiv="Content-Security-Policy" content="default-src 'self' ">-->
    <!--<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: cdvfile: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">		-->

Does this StackOver question help?

Thank you but it did not help me…

I saw something like below but I dont know how to set “AllowFileAccess” to “true”:

“Now (android sdk version from 29 to 30) you will have to call setAllowFileAccess(true) in the settings of the webview to make it work. The default value was true for sdk 29 and lower versions, but now you will have to allow the access yourself.”

Looking in the Cordova-android repo, I see these fixes:

I am sorry but I dont know what I have to do…

Give this a shot in config.xml: <engine name="android" spec="10.1.1" />

Edit: I see you already have this line targeting 9.0.0. So just change it to 10.1.1

Also, remove this unnecessary line… even though it wont cause problems: <preference name="phonegap-version" value="cli-9.0.0" />

Now… I cant login:

jquery-3.1.0.min.js:4 Mixed Content: The page at ‘https://localhost/index.html’ was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ‘http://diagsystem.odontoscan.com.br:8083/OdontoScanServerv0-0-64/rest/acessows/getinformacoesacesso’. This request has been blocked; the content must be served over HTTPS.

That looks like a configuration problem on the site you are trying to access.

Hi, I add this in config.xml and I could login again:
<preference name="scheme" value="http" />

But I still get:
/data/user/0/br.com.harscan/cache/IMG_20211207_100641444.jpg?1638969242026:1 GET file:///data/user/0/br.com.harscan/cache/IMG_20211207_100641444.jpg?1638969242026 net::ERR_ACCESS_DENIED

Looks like you’re making progress. Does your content-security-policy allow for accessing file://?

Also, see this:
https://cordova.apache.org/docs/en/10.x/guide/appdev/allowlist/#navigation-allow-list

I am using this way: <allow-navigation href="file:*" />

Now the error message changed a little bit:

index.html:1 Not allowed to load local resource: file:///data/user/0/br.com.harpia.odontoscan/cache/Teste.jpg?1639497813438
index.html:1 Not allowed to load local resource: file:///data/user/0/br.com.harpia.odontoscan/cache/Teste.jpg?1639497813438
index.html:1