Jump to content
Sign in to follow this  
Michael Collier

How to: Enable camera in TWebBrowser

Recommended Posts

Hello,

 

I have a javascript based webpage that allows me to open my USB camera, but when I open the webpage via Delphi RAD TWebBrowser component it doesn't work (testing on Android phone).

 

I wasn't surprised because when I hosted this webpage in an <iframe> as part of a simple web based application I needed to "turn on" certain security features i.e. allow="camera" etc

 

So I'm guessing I need to do similar for TWebBrowser but can't find how to do that? 

 

I tried modifying the security configuration for the app on my Android phone (allow camera access), but still didn't work.

 

Is there another setting - either a property/function of TWebBrowser - or maybe there are security settings I need to configure for the application from within RAD before compiling?

 

Thanks in advance,

Mike

 

 

 

 

 

 

Share this post


Link to post

Although this demo is related to being able to upload files: https://github.com/DelphiWorlds/Kastri/tree/master/Demos/WebBrowserFileChooser

 

It also has code that should help you, based on this answer on SO: https://stackoverflow.com/a/47525818/3164070

 

Please be aware that it requires a Java library (https://github.com/DelphiWorlds/Kastri/blob/master/Lib/dw-webchromeclient.jar, which has been added to the demo)

 

Looking at it now, I figure there should be comments in the code explaining exactly what it is doing 🙂

 

Share this post


Link to post

Thanks Dave,

 

Looking at the SO thread it mentions overriding onPermissionRequest (I guess in Android Studio) but I'm not sure what Delphi 11 equivalent is?

 

I downloaded the WebBrowserFileChooser project, I'm working my way through the code, looking at TWebChromeClientManager etc, is this related to working with onPermissionRequest ?

 

From my own experiments I have figured out that the audio is giving me the problem, (I can get video working now 🙂 ). I found others with same problem and more references to onPermissionRequest .

 

I have uploaded a simple HTML test page for opening a camera & microphone and reporting any errors in a textbox.

https://iotleaf.co.uk/test/browser/mic/

If anyone tries opening the test page with their own installation of Embarcadero WebBrowser demo..

C:\Users\Public\Documents\Embarcadero\Studio\22.0\Samples\Object Pascal\Mobile Snippets\WebBrowser

They will see the problem..

 

I modified my copy of the WebBrowser project AndroidManifest.template.xml file to include audio and camera, thus..

<%uses-permission%>
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />

 

So I'm getting closer, I think I just need to figure the onPermissionRequest part? 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×