I'm building a Native-Android/WebView-App thats code is hosted on a remote server (in HTML and Javascript).
The Web App has a function that launches the phone's camera via a HTML form, input request:
<form action="#" method="post" enctype="multipart/form-data" >
<input name="image" type="file" accept="image/*" capture/>
</form>
This feature works perfectly well in the standard Android web browser but not in the Native App WebView browser.
I have enabled the following permissions in the Native app manifest but still can't get the camera to launch:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
Failing getting this feature to work, I would accept being able to access the camera roll instead so that a user could simply select a photo they have already taken but I would rather launch the camera the way it does in the standard web browser.
Can anyone help please?
While accessing Camera from Webview, it asks for permissions and we can grant them by overriding the onPermissionRequest. Also make sure to take care of runtime permissions.
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(PermissionRequest request) {
request.grant(request.getResources());
}
});
Also, make sure this property is disabled
webSettings.setMediaPlaybackRequiresUserGesture(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With