Android: Inputstream

Asked

Viewed 103 times

1

There’s a way I can change:

InputStream is = getAssets().open("xxx.html");

for:

InputStream is = ("http://www.xxx.com.br/xxx.html");

Maybe using Httpurlconnection but don’t know how to implement.

Follow a piece of my code where I want to implement this:

try {
     InputStream is = getAssets().open("xxx.html");
     String data = getResultFromStream(is);

     WebSettings ws = webView.getSettings();
     ws.setJavaScriptEnabled(true);
     ws.setJavaScriptCanOpenWindowsAutomatically(true);
     ws.setDomStorageEnabled(true);

     MyWebChromeClient chromeClient = new MyWebChromeClient();
     MyWebViewClient webViewClient = new MyWebViewClient();

     webView.setWebChromeClient(chromeClient);
     webView.setWebViewClient(webViewClient);
     webView.setBackgroundColor(0);
     webView.loadData(data, "text/html", "UTF-8");

     } catch (IOException e) {
        e.printStackTrace();
     } catch (Exception e) {
        e.printStackTrace();
     }

1 answer

1


Try to use

try {


 WebSettings ws = webView.getSettings();
 ws.setJavaScriptEnabled(true);
 ws.setJavaScriptCanOpenWindowsAutomatically(true);
 ws.setDomStorageEnabled(true);

 MyWebChromeClient chromeClient = new MyWebChromeClient();
 MyWebViewClient webViewClient = new MyWebViewClient();

 webView.setWebChromeClient(chromeClient);
 webView.setWebViewClient(webViewClient);
 webView.setBackgroundColor(0);
 webView.loadUrl("http://www.xxx.com.br/xxx.html");

 } catch (IOException e) {
    e.printStackTrace();
 } catch (Exception e) {
    e.printStackTrace();
 }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.