In my android app, I am trying to load a webpage (that must access the camera) on WebView
. On my laptop, when I load the webpage, I could access the camera.
Everything else on the html
page is shown.
Here are the permission I am putting in the Manifest.xml
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.webkit.PermissionRequest" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" />
I am setting the SDK as follow:
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="21" />
Here is my webview setting:
private void setMyWebviewSettings(WebSettings MyWebviewSettings) { MyWebviewSettings.setAllowFileAccessFromFileURLs(true); MyWebviewSettings.setAllowUniversalAccessFromFileURLs(true); MyWebviewSettings.setJavaScriptCanOpenWindowsAutomatically(true); MyWebviewSettings.setJavaScriptEnabled(true); MyWebviewSettings.setDomStorageEnabled(true); MyWebviewSettings.setJavaScriptCanOpenWindowsAutomatically(true); MyWebviewSettings.setBuiltInZoomControls(true); MyWebviewSettings.setAllowFileAccess(true); MyWebviewSettings.setSupportZoom(true); }
If I could access the camera from my app directly (using a normal activity), why can't I open it from within the WebView
?!
Embedding in an Android App requires the use of the WebView class. To allow EnableX to access the camera, follow the steps given below: Override WebChromeClient.
Within the shouldOverrideUrlLoading() method simply get the URL from the request and pass into the Intent. See the full example.
I was trying same thing. Below code worked to me.
First in manifest file we have to add camera hardware permission true using uses permission tag.
Then need to accept camera permission to use using below lines in your activity.
webview.setWebChromeClient(new WebChromeClient() { @Override public void onPermissionRequest(final PermissionRequest request) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { request.grant(request.getResources()); } } });
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