Home » Android » android – how to load http url with instantApp webview?

android – how to load http url with instantApp webview?

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’m trying to make an instantApp and put a webView at the opening activity.
When I add a url starts with https I can see the website on my webview.
but when the url starts with http, I get an error:

net::ERR_CLEARTEXT_NOT_PERMITTED

Here is my code:

public class HelloActivity extends AppCompatActivity {

WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hello);

    webView = (WebView)findViewById(R.id.webView1);
    webView.setWebViewClient(new WebViewClient());


    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);

    webView.loadUrl("http://www.foxnews.com/");

    // webView.loadUrl("https://www.google.com"); this url is working


  }
}

Hope you can help me with that.

How to&Answers:

With reference to android Instant-App Document

All the network traffic from inside instant apps must use HTTPS. Instant apps does not support HTTP.