Reputation: 2996
I have a web page that is opening in android webview. The requirement is to launch Camera directly on tapping file chooser.
I have written following code for selecting image:
<input id="files" type="file" name="images[]" multiple accept="image/*" capture="camera"/>
This works fine in chrome browser and opens camera for capturing image. But, when same page is called inside webview, it asks for choose from Camera, Gallery and similar apps.
Upvotes: 3
Views: 16043
Reputation: 131
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(final PermissionRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
request.grant(request.getResources());
}
}
});
Upvotes: 0
Reputation: 1414
Take a look at this repo on Github which is an example of how to to upload and process images/videos in a Webview-based app.
Don't forget to add this in your AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
If you have any more question just ask. I hope it solves your problem.
Upvotes: 3
Reputation: 1462
As suggested here (FAQ part): https://developer.chrome.com/multidevice/webview/overview input type and media capture are not supported out of the box. Maybe this helps you implementing it on your own: Open camera for input type file in Webview not opening Android
Upvotes: 0