Bogdan Iacob
Bogdan Iacob

Reputation: 73

Permissions webview android

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.

Upvotes: 4

Views: 11052

Answers (2)

Mehdi
Mehdi

Reputation: 775

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.

Upvotes: 6

RoyalGriffin
RoyalGriffin

Reputation: 2007

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.

Upvotes: 0

Related Questions