3

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?

CaptainJ
  • 157
  • 3
  • 11

2 Answers2

2

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);
VickyAbishek
  • 53
  • 1
  • 6
-3

Use Javascript interface to launch camera.

Or

You can use cordova Framework.

Sachin Chandil
  • 17,133
  • 8
  • 47
  • 65