Enabling All Permissions Automatically in A WebVie
Enabling All Permissions Automatically in A WebVie
Overview
In Android, a WebView app does not automatically get all permissions enabled by default.
Permissions such as camera, microphone, location, and storage must be explicitly requested and
granted by the user at runtime, in addition to being declared in the AndroidManifest.xml file.
There is no supported or secure way to have all permissions "auto-enabled" without user
interaction, due to Android's privacy and security model. However, you can streamline the
permission flow as much as possible within these constraints.
Grant in WebChromeClient Override onPermissionRequest and call grant() Automatic (if allowed)
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(final PermissionRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
request.grant(request.getResources());
}
}
});
Ensure the app already has camera permission, or this will fail with a SecurityException [1] .
Conclusion
You cannot have all permissions "auto-enabled" for a WebView app without explicit user
consent due to Android's security model. The recommended approach is:
Declare all needed permissions in the manifest.
Prompt the user for runtime permissions.
Automatically grant web-origin permission requests in onPermissionRequest if the app
already has the required permissions.
This is the most streamlined, compliant way to enable permissions for a WebView app on
Android [2] [1] .
⁂
1. https://stackoverflow.com/questions/40659198/how-to-access-the-camera-from-within-a-webview
2. https://developer.android.com/training/permissions/requesting
3. https://github.com/pichillilorenzo/flutter_inappwebview/issues/1638
4. https://github.com/react-native-webview/react-native-webview/issues/3733