ikevin8me
ikevin8me

Reputation: 4313

Implementing WebRTC on WebView with Codename One

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!

Upvotes: 3

Views: 555

Answers (1)

steve hannah
steve hannah

Reputation: 4716

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.

Upvotes: 3

Related Questions