Android Question How can I get the webview to accept camera permission from my Gethub website?

tekh2999

Member
Licensed User
Longtime User
I have a AR website that works great on my desktop. It also works on my mobile if I use the chrome browser. How can I get the webview to accept the permission? In a B4X webview. What am i doing wrong here. I get The page at "https://tekh3999.gethub.io" says"

Webcam Error
Name: NotAllowedError
Message: Permission denied

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    
'cam stuff
    Private frontCamera As Boolean = False
    Dim phid As PhoneId
    Dim rp As RuntimePermissions
    
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    
    Dim wv As WebView
    Dim wve As WebViewExtras
    Dim wvs As WebViewSettings
    Private ime1 As IME

    Private ActivityParent As JavaObject
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    
    wv.Initialize("wv")
            
    wve.addWebChromeClient(wv,"wve")
    wvs.setAllowFileAccess(wv,True)
    wvs.setAppCacheEnabled(wv,True)
    wvs.setDOMStorageEnabled(wv,True)
    
    Activity.AddView(wv,0,0,100%x,100%y)
    
    wv.LoadUrl("https://tekh3999.github.io/tekh3999ar7.github.io/")
    Log("tried to connect")
    
     ime1.Initialize("ime1")
    ime1.AddHeightChangedEvent
    Dim jo As JavaObject = wv
    Dim settings As JavaObject = jo.RunMethod("getSettings", Null)
    jo.InitializeContext
    'jo.RunMethod("SetChrome", Array(wve))
    
    Dim r As Reflector
    r.Target = settings
    r.RunMethod2("setAllowUniversalAccessFromFileURLs", True, "java.lang.boolean")
    
 End Sub

Sub Activity_Resume
    For Each permission As String In Array (Starter.rp.Permission_CAMERA)
        Starter.rp.CheckAndRequest(Starter.rp.Permission_CAMERA)
        wait for Activity_PermissionResult (permission As String, Result As Boolean)
        
        
        If Result = False Then
            ToastMessageShow("No permission!", True)
        Log("no Permission")
            Activity.Finish
            Return
            Else
                If Result = True Then
                    
                
                End If
                
                    End If
        
    Next     
End Sub

Sub Activity_PermissionResult (Permision As String, Result As Boolean)
    
    If Permision = Starter.rp.PERMISSION_CAMERA Then
         Activity_PermissionResult (Permision, True)
         Result = True
            End If

End Sub
 
Sub client_ReceivedSslError(SslErrorHandler1 As SslErrorHandler, SslError1 As SslError)
    Log(SslError1)
    SslErrorHandler1.Proceed
End Sub

Sub IME1_HeightChanged (NewHeight As Int, OldHeight As Int)
 
End Sub

 

Sub AfterChange
    Dim ajo As Panel = Activity
    Dim width As Int = ActivityParent.RunMethod("getMeasuredWidth", Null)
    Dim height As Int = ActivityParent.RunMethod("getMeasuredHeight", Null)
    If width = 0 Or height = 0 Then Return
    ajo.width = width 'update the "activity" width and height
    ajo.height = height
    wv.width = width
    wv.height = height
End Sub

Sub Activity_Pause (UserClosed As Boolean)
 
End Sub


'    the official google vr library documentation recommends to call the Shutdown() method before the activity is destroyed
'    we'll use inline java to ensure that the Shutdown() method is called

 
 #if java

 
#End If
 

tekh2999

Member
Licensed User
Longtime User

I've tried to run that example multiple times and other webrtc example. They all give me the same error:

B4A Version: 8.50
Parsing code. (0.01s)
Building folders structure. (0.04s)
Compiling code. (0.01s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Generating R file. (0.05s)
Compiling generated Java code. Error
B4A line: 17
End Sub
src\b4a\example\main.java:481: error: cannot find symbol
public void onPermissionRequest(PermissionRequest request) {
^
symbol: class PermissionRequest
location: class MyChromeClient


Am I missing a step or a library to this, cause it never compiles for me.
 
Last edited:
Upvote 0

tekh2999

Member
Licensed User
Longtime User
No it wasn't. I was on platform 19 still for some reason. I switch to 28 and my app now works, Awesome. problem solved. I Now have a working Augmented Reality application. Thank you Erel
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

tekh2999

Member
Licensed User
Longtime User
Sounds like you are using an old SDK Installation.
As far as i know it is no longer compatible and everyone needs to setup a new SDK. Especially when using maven artifacts.

You can find the setup instructions here:
https://www.b4x.com/b4a.html#installation
Right Don. Updating my sdk is something I do always in the sdk manager. Updating the platform was just one of the steps I missed. After doing this for so long it becomes repetitive and you sometimes forget certain steps. Thats why its always good to ask questions. Thanks for your help.
 
Last edited:
Upvote 0

tekh2999

Member
Licensed User
Longtime User
AR_example.jpg
Ok had to clean it up a little bit but here is my augmented reality project working in a B4A webview. This is not in a Chrome browser or Firefox or Opera. This is B4a application. So far no issues. Now that this hurdle has been solved. I guess the next thing is to try and get this project as a wrapper in B4a. but my knowledge of creating the library is limited.
 

Attachments

  • My AR app.gif
    My AR app.gif
    4.3 KB · Views: 346
Last edited:
Upvote 0
Top