Implementing WebRTC on WebView with Codename One

醉酒当歌 提交于 2019-12-10 11:26:45

问题


I'm developing an app which I need to include WebRTC using the WebView of Android. According to this article: [https://developer.chrome.com/multidevice/webview/overview] it is fully supported since WebView v36. (I'm testing on an Android 5.1.1 / Chrome 54 / Mobile Safari 537.36. And I confirm that it works on the standalone Chrome browser).

As of now, viewing of WebRTC works.

However, broadcasting (capturing video from the camera and sending it to the server) does not work. Note: it works on the standalone Chrome on the same Android.

I've included all these permissions in the codenameone_settings.properties file:

android.xpermissions=<uses-permission android:name="android.permission.CAMERA" android:required="true"/>\
  <uses-permission android:name="android.permission.RECORD_AUDIO" android:required="true" />\
  <uses-permission android:name="android.permission.INTERNET" android:required="true" />\
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="true" />\
  <uses-permission android:name="android.permission.CAMERA" android:required="true" />\
  <uses-feature android:name="android.hardware.audio.low_latency" android:required="true" />\
  <uses-feature android:name="android.hardware.audio.pro" android:required="true" />\
  <uses-feature android:name="android.hardware.microphone" android:required="true"/>\
  <uses-feature android:name="android.hardware.camera" android:required="true" />\
  <uses-feature android:name="android.hardware.camera.autofocus" android:required="true"/>\
  <uses-feature android:name="android.hardware.camera" android:required="true" />\
  <uses-feature android:name="android.hardware.camera.front" android:required="true" />
  1. Is this the way to activate all the necessary Android permissions.
  2. What do you think is causing the WebRTC not to function properly?

The WebView is called by the BrowserComponent class.

I understand that Android code is translated to native code and I believe that there is a way to make it work. Thanks!


回答1:


I just took a look at a couple of examples (here and here, and it looks like the webview needs to grant some permissions in order to allow webrtc to work.

I have made a small change to our Android port that should allow you to grant these permissions. You just need to specify the origin in which permissions should be allowed. You would do this by setting the "android.WebView.grantPermissionsFrom" display property to the URL (or space delimited URLs) that you want to grant the permissions on.

e.g.


Display.getInstance().setProperty(
        "android.WebView.grantPermissionsFrom", 
        "https://www.example.com/"
);

Call this in your app's init() or start() method.

NOTE These changes won't be available until the next server update. I'm not sure exactly when that will be since the bootcamp is underway right now. Usually it is every Friday, but it may be delayed until the first week of May due to the bootcamp.



来源:https://stackoverflow.com/questions/43541962/implementing-webrtc-on-webview-with-codename-one

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!