Android Question Ultimate Webwiew2 problem with camera

kohlenach

Member
Hi I changed the first Example from ultimate webview 2 to check the camera.
It opens a dialog : Choose app. See screenshot.
Every app is working file selector, gallery, accept the camera app dont open.

What can I do.

rgs
J.






B4X:
ultimateWebView1.LoadHTMLString( $"
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    </head>
    <body>
    <h1>Camera Test</h1>
    <input Type="file" id="mypic" accept="image/*" capture="camera">
    <canvas></canvas>
    <br>
    <script>
    var input = document.querySelector('input[type=file]'); // see Example 4
    input.onchange = function () {
    var File = input.files[0];
    //upload(File);
    drawOnCanvas(File);   // see Example 6
    //displayAsImage(File); // see Example 7
    };
   
    function upload(File) {
    var form = new FormData(),
    xhr = new XMLHttpRequest();
   
    form.append('image', file);
    xhr.open('post', 'server.php', true);
    xhr.send(form);
      }
   
    function drawOnCanvas(File) {
    var reader = new FileReader();
    reader.onload = function (e) {
    var dataURL = e.target.result,
    c = document.querySelector('canvas'), // see Example 4
    ctx = c.getContext('2d'),
    img = new Image();
   
    img.onload = function() {
    c.width = img.width;
    c.height = img.height;
    ctx.drawImage(img, 0, 0);
    };
   
    img.src = dataURL;
    };
   
    reader.readAsDataURL(File);
      }
   
    function displayAsImage(File) {
    var imgURL = URL.createObjectURL(File),
    img = document.createElement('img');
   
    img.onload = function() {
    URL.revokeObjectURL(imgURL);
    };
   
    img.src = imgURL;
    document.body.appendChild(img);
      }
    </script>
    <!-- source: http://www.w3.org/TR/html-media-capture/ -->
    </body>
    </html>
   
   
    "$)


Image 2024-05-17 at 20.47.45.jpeg
 

kohlenach

Member
When I debug the app, I see that the function for the permission request is not used:
B4X:
Private Sub UltimateWebView1_PermissionsRequest (RequestedRuntimePermissions As List, Request As PermissionRequest) 'Works from API level 21 and above.
    For Each permission As String In RequestedRuntimePermissions
        Log(permission)
        rp.CheckAndRequest(permission)
        Wait For B4XPage_PermissionResult (permission As String, Result As Boolean)
        If Result=False Then
            Request.Deny
            Return
        End If
    Next
    Request.Grant(Request.Resources)
End Sub

So I added the following permission request in the B4XPage_Created() function:

B4X:
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
        Return
    End If

NOW IT WORKS !

What I dont understand is :

There is a entry in the manifest:
AddPermission(android.permission.CAMERA)

Why android dont ask for the permission ?


rgs
J.
 
Upvote 0
Top