Example usage for android.webkit WebView loadUrl

List of usage examples for android.webkit WebView loadUrl

Introduction

In this page you can find the example usage for android.webkit WebView loadUrl.

Prototype

public void loadUrl(String url, Map<String, String> additionalHttpHeaders) 

Source Link

Document

Loads the given URL with the specified additional HTTP headers.

Usage

From source file:net.basov.ticketinfo.UI.java

public void displayWelcomeScreen(final WebView wv) {
    SharedPreferences defSharedPref = PreferenceManager.getDefaultSharedPreferences(wv.getContext());

    setWelcome("s_lang", defSharedPref.getString(wv.getContext().getString(R.string.pk_app_lang),
            wv.getContext().getString(R.string.pref_lang_def)));
    if (defSharedPref.getBoolean(wv.getContext().getString(R.string.pk_transliterate_flag), false)) {
        setWelcome("s_translit", "<input type=\"checkbox\" disabled=\"disabled\" checked=\"checked\">");

    } else {/*from w ww.  ja  va 2 s  .  c o  m*/
        setWelcome("s_translit", "<input type=\"checkbox\" disabled=\"disabled\">");
    }
    if (defSharedPref.getBoolean(wv.getContext().getString(R.string.pk_send_platform_info), true)) {
        setWelcome("s_sendinfo", "<input type=\"checkbox\" disabled=\"disabled\" checked=\"checked\">");
    } else {
        setWelcome("s_sendinfo", "<input type=\"checkbox\" disabled=\"disabled\">");
    }
    if (defSharedPref.getBoolean(wv.getContext().getString(R.string.pk_use_view_directory), false)) {
        setWelcome("s_use_view_directory",
                "<input type=\"checkbox\" disabled=\"disabled\" checked=\"checked\">");
    } else {
        setWelcome("s_use_view_directory", "<input type=\"checkbox\" disabled=\"disabled\">");
    }

    wv.setWebViewClient(new MyWebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(wv, url);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                view.evaluateJavascript("javascript:jreplace('" + welcome_json.toString() + "')", null);
            } else {
                view.loadUrl("javascript:jreplace('" + welcome_json.toString() + "')", null);
            }
            wv.clearCache(true);
            wv.clearHistory();
        }
    });
    Context c = wv.getContext();
    wv.loadUrl("file:///android_asset/" + c.getString(R.string.welcome_ui_file));
}

From source file:com.facebook.react.views.webview.ReactWebViewManager.java

@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
    if (source != null) {
        if (source.hasKey("html")) {
            String html = source.getString("html");
            if (source.hasKey("baseUrl")) {
                view.loadDataWithBaseURL(source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING,
                        null);/*from www.j  av a  2s.  co m*/
            } else {
                view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
            }
            return;
        }
        if (source.hasKey("uri")) {
            String url = source.getString("uri");
            String previousUrl = view.getUrl();
            if (previousUrl != null && previousUrl.equals(url)) {
                return;
            }
            if (source.hasKey("method")) {
                String method = source.getString("method");
                if (method.equals(HTTP_METHOD_POST)) {
                    byte[] postData = null;
                    if (source.hasKey("body")) {
                        String body = source.getString("body");
                        try {
                            postData = body.getBytes("UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            postData = body.getBytes();
                        }
                    }
                    if (postData == null) {
                        postData = new byte[0];
                    }
                    view.postUrl(url, postData);
                    return;
                }
            }
            HashMap<String, String> headerMap = new HashMap<>();
            if (source.hasKey("headers")) {
                ReadableMap headers = source.getMap("headers");
                ReadableMapKeySetIterator iter = headers.keySetIterator();
                while (iter.hasNextKey()) {
                    String key = iter.nextKey();
                    if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
                        if (view.getSettings() != null) {
                            view.getSettings().setUserAgentString(headers.getString(key));
                        }
                    } else {
                        headerMap.put(key, headers.getString(key));
                    }
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }
    view.loadUrl(BLANK_URL);
}