WebView Permissions
Updated iOS WebView Permissions: Camera and Gallery Permissions
Updated iOS WebView Permissions: Camera and Gallery Permissions
Updated Android WebView Permissions as of Apr 25': Camera Permissions. Includes Java implementation.
Updated Android WebView Permissions as of Apr 25': Camera Permissions. Includes Java implementation.
Below is a detailed description of how to implement permission handling for Android WebView so that the web app can access the camera (and, if needed, the microphone):In this example, all requested resources are immediately granted. While this approach is acceptable for testing, it is not recommended for production due to security concerns.In your code, you need to map the requested resources to the corresponding Android permissions to properly request them from the user.These entries indicate that your application uses the camera and audio, while also declaring that the camera hardware is not mandatory for the app to function.
1. Interaction Between WebView and Permissions
When a web page requests access to the camera or microphone, the WebView calls the onPermissionRequest callback method of the WebChromeClient. This method receives a PermissionRequest object containing the list of resources (permissions) requested by the web page. For more detailed information, please refer to the documentation.A basic implementation of handling this request might look like:2. Mapping Permission Types
The PermissionRequest object may request different types of permissions. For example:3. Adding Permissions to the Manifest
To allow your application to use the camera and audio, you must declare the appropriate permissions and features in your AndroidManifest.xml. For example, to support the permissions mentioned above, add the following:4. Requesting Dangerous Permissions at Runtime
Permissions such as CAMERA and RECORD_AUDIO are classified as “dangerous” and must be requested from the user at runtime. An example implementation using ActivityResultContracts.RequestPermission is provided below:Key Points of the Implementation:
- Requesting Permissions: When a permission request is received via onPermissionRequest, a coroutine is launched that uses the PermissionRequester object to request the necessary dangerous permissions from the user.
- Handling the Result: If at least one of the required permissions is granted, the app calls request.grant with the corresponding resources; otherwise, it calls request.deny.
- Permission Mapping: The WebViewPermissions enum is used to map the permissions requested by the PermissionRequest to the actual Android permissions.
Java implementation
Conclusion
To enable WebView to use the camera, you need to:- Implement the onPermissionRequest method in a WebChromeClient.
- Map the permission types from the PermissionRequest to Android permissions (e.g., camera and audio).
- Declare the required permissions and features in the AndroidManifest.xml.
- Request dangerous permissions from the user at runtime before granting them to WebView.
Android WebView: Files/Gallery Permissions
Android WebView: Files/Gallery Permissions
To be able select image files to provide it to web app the following steps should be done. Note: our web app supports only images to be selected. Other file types such as PDF are not supported.
- Custom web chrome client should be set to your android WebView:
onShowFileChoosershould be overridden to be able to open your file chooser:
- We suggest using the Android file chooser — it requires no permissions to access images. If you use a custom file chooser, you have to handle all the required permissions yourself. To open the Android file chooser, use the following code:
Checkout flow
The Checkout session request, payment method display, and code snippets should be integrated in the same way as in the Online Custom Integration. When customers complete the Tabby checkout (whether the payment is successful, rejected, or cancelled), you can handlemerchant_urls, listen to checkout events passed in the WebView, or manage webhooks received on the app backend.
Below is an example of the WebView events handling for iOS (Swift):
tabby-ios-manual-integration.md