I'm working on a mobile app that has a video chat feature. I found a nice javascript library for webrtc, which seems to load just fine in QWebView
but I need to give it permission to access the camera and microphone and I can't figure out how to do that. Is it possible? QWebEngineView
has a handy signal and slot for that, but it's not supported for mobile.
Manifest permissions are not working as described here.
Corresponding Qt bug: cant access camera and mic with QML WebView
Any ideas?
Qt has implemented Android's permission model in version 5.10.
See here: http://doc.qt.io/qt-5/qtandroid.html.
The functions you have to use are:
If you want to access a camera and microphone you have to request the permissions before using. Example:
QStringList perms;
perms << "android.permission.CAMERA" << "android.permission.RECORD_AUDIO";
QtAndroid::checkPermissions(perms, [](const PermissionResultMap& resMap) {
foreach(const QString &key, resMap.keys()) {
qDebug() << "Result of permission" << key << ":" << resMap[key];
}
});
We resolved this QT bug by recompiling QT code and updating corresponding jars. We downloaded QT Source code for Android using Maintenance tool. While going through QT source code we found that due to some reason Qt developers are not overriding onPermissionRequest()
of WebCromeClient
due to which WebView is not allowing Media access to JS functions. Please follow following steps to resolve issue.
Download QT Source code.
Update code in QtAndroidWebViewController.java
. This class is located at ~/Qt/5.10.0/Src/qtwebview/src/jar/src/org/qtproject/qt5/android/view.
Add following function to inner class QtAndroidWebChromeClient
.
@Override public void onPermissionRequest(PermissionRequest request) { request.grant(request.getResources()); }
Depending on your Android sdk you may need to Comment/Change
deprecated functions for older versions of Android. Also you can change
few of the methods in QtAndroidWebViewClient
as per new versions of
Android.
Then import project ~/Qt/5.10.0/Src/qtwebview In your Qt creator, You may need some Java knowledge to resolve issues(if you get some build issues)
Depending on your build folder path Settings, successful build project will generate two jars in path build_folder/jar QtAndroidWebView.jar
, QtAndroidWebView-bundled.jar
.
Replace jars in path ~/Qt/5.10.0/android_armv7/jar/.
Now rebuild(Clean build) your original project, which is using WebView and issue is Resolved.
Note: Path may change depending on QT Download Path and Operating System, but built jar can be replaced on any System(as java jars).
If QT resolves this issue in Next release we can replace Updated jars.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With