Camera not opening in WebView
If you want to use the camera in your website with (html5):
<input type="file" accept="image/*" capture="camera">
First of all add this line into your Manifest:
<uses-permission android:name="android.permission.CAMERA" />
Then you need to config you webview in android like this:
- enable java script
- enable the DOM storage
PermissionRequest (This class defines a permission request and is used when web content requests access to protected resources)
webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setDomStorageEnabled(true); webview.getSettings().setPluginState(WebSettings.PluginState.ON); webview.setWebChromeClient(new WebChromeClient(){ // Need to accept permissions to use the camera @Override public void onPermissionRequest(final PermissionRequest request) { L.d("onPermissionRequest"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { request.grant(request.getResources()); } } });
I got your issue i think you need to add <uses-feature>
for camera like:
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
It's becoz requesting the permission
grants your application access to the appropriate hardware and software, while declaring the features
used by your application ensures proper device compatibility.
Try this and give me feedback on this. For more information go to http://developer.android.com/guide/topics/manifest/uses-feature-element.html
I did what @manuel suggested, but still, I couldn't get it to work on looking into the log I found we also had to add
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);