3

I'm new on this community and I hope you can help me. I'm trying to create a WebView app that contains a WebRTC. My problem, I suppose that is I have no idea how to request the web permissions in app. Maybe the problem is other. Anyway when I run the app I see this.

I want to make this "play" image disappear:

and show this thing that is the original webpage

Thanks in advance.

Bogdan Iacob
  • 63
  • 1
  • 4
  • That image most likely means you have a – Mehdi Jun 28 '18 at 20:18
  • Ok. Could you explaint me a little how to remove or hide the – Bogdan Iacob Jun 29 '18 at 15:09
  • See my answer, I tried to elaborate. – Mehdi Jun 29 '18 at 15:37

2 Answers2

5

If your webview doesn't load an external page (from the internet) you don't need any permission, otherwise you only need the internet permission:

<uses-permission android:name="android.permission.INTERNET" /> 

That image means you probably have an HTML <video> tag on your HTML page, which is taking the whole screen (height - width), and which is declared as an auto-playing video, by default Android blocks Auto-playing videos.

Example:

<video controls autoplay>
    <source src="movie.mp4" type="video/mp4">
</video>

So,

1- Make sure you use the WebChromeClient

2- Here's a method to initialize your webview:

@SuppressLint ("SetJavaScriptEnabled")
private void initWebview () {
    webview = findViewById (R.id.my_webview);

    webView.setWebChromeClient (new WebChromeClient () {

        @Override
        public boolean onConsoleMessage (ConsoleMessage consoleMessage) {
            Log.e ("WebView - Logger", consoleMessage.messageLevel () + " : " + consoleMessage.lineNumber () + " : " + consoleMessage.message ());
            return true;
        }
    });

    WebSettings webSettings = webView.getSettings ();
    webSettings.setJavaScriptEnabled (true);
    webSettings.setUseWideViewPort (true);
    webSettings.setLoadWithOverviewMode (true);
    webSettings.setCacheMode (WebSettings.LOAD_NO_CACHE);
}

3-

  • If you wanna allow whatever HTML video in your pages to be played automatically (like probably in your case), without showing that big "Play" image add to your initWebview method: webSettings.setMediaPlaybackRequiresUserGesture (false);

  • If you don't want to allow the autoplaying remove the autoplay attribute from the <video> tag in your HTML page.

Mehdi
  • 765
  • 9
  • 19
0

You don't need any special permission to display a WebView. You just need the internet permission, to load that web page. For asking that see this post.

RoyalGriffin
  • 1,987
  • 1
  • 12
  • 25