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) 

Source Link

Document

Loads the given URL.

Usage

From source file:de.mkrtchyan.recoverytools.SettingsFragment.java

public static void showChangelog(Context AppContext) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(AppContext);
    dialog.setTitle(R.string.changelog);
    WebView changes = new WebView(AppContext);
    changes.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    changes.setWebViewClient(new WebViewClient());
    changes.loadUrl(Constants.CHANGELOG_URL);
    changes.clearCache(true);/*  w ww.j  av a2s . co  m*/
    dialog.setView(changes);
    dialog.show();
}

From source file:Main.java

public static void execIsEnabledCallbackCommand(final WebView webView, final String commandName,
        final String isEnabled) {
    if (webView == null) {
        return;//from   w  ww.jav  a 2  s .c  o  m
    }

    webView.post(new Runnable() {
        @Override
        public void run() {
            String command = "javascript:" + commandName + "(" + isEnabled + ");";
            webView.loadUrl(command);
        }
    });
}

From source file:Main.java

static void paramLoader(WebView view, String url) {
    UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
    sanitizer.setAllowUnregisteredParamaters(true);
    sanitizer.parseUrl(url);// w  ww . j  ava 2  s .c  o m
    String param = sanitizer.getValue("pageload");
    if (param != null) {
        switch (param) {
        case "composer":
            view.loadUrl(
                    "javascript:(function()%7Btry%7Bdocument.querySelector('button%5Bname%3D%22view_overview%22%5D').click()%7Dcatch(_)%7B%7D%7D)()");
            break;
        case "composer_photo":
            view.loadUrl(
                    "javascript:(function()%7Btry%7Bdocument.querySelector('button%5Bname%3D%22view_photo%22%5D').click()%7Dcatch(_)%7B%7D%7D)()");
            break;
        case "composer_checkin":
            view.loadUrl(
                    "javascript:(function()%7Btry%7Bdocument.querySelector('button%5Bname%3D%22view_location%22%5D').click()%7Dcatch(_)%7B%7D%7D)()");
            break;
        case "composer_top":
            view.scrollTo(0, 0);
            break;
        default:
            break;
        }
    }

}

From source file:Main.java

public static void call(WebView webview, String function, List<String> paramList) {
    String paramString = "";
    if (paramList != null) {
        for (String param : paramList) {
            if (paramString.equals(""))
                paramString = "'" + param + "'";
            else// ww  w  . j  a  v a2  s. c om
                paramString = ",'" + param + "'";
        }
    }

    webview.loadUrl("javascript:" + function + "(" + paramString + ")");
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

@SuppressLint("SetJavaScriptEnabled")
private static void callInternalBrowser(AdWebView webView, Uri uri) {
    String urlParam = uri.getQueryParameter("url");

    if ((webView.getContext() == null) || (urlParam == null) || (!urlParam.startsWith("http"))) {
        return;//w ww . jav  a 2s.  com
    }

    String url = Uri.decode(urlParam);
    Class<?> activity_clz = AdActivity.getActivityClass();

    Intent intent = new Intent(webView.getContext(), activity_clz);
    intent.putExtra(AdActivity.INTENT_KEY_ACTIVITY_TYPE, AdActivity.ACTIVITY_TYPE_BROWSER);

    WebView browserWebView = new WebView(webView.getContext());
    WebviewUtil.setWebViewSettings(browserWebView);
    BrowserAdActivity.BROWSER_QUEUE.add(browserWebView);
    browserWebView.loadUrl(url);

    if (webView.adView.getBrowserStyle() != null) {
        String i = "" + browserWebView.hashCode();
        intent.putExtra("bridgeid", i);
        AdView.BrowserStyle.bridge
                .add(new Pair<String, AdView.BrowserStyle>(i, webView.adView.getBrowserStyle()));
    }

    try {
        webView.getContext().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(webView.getContext(), R.string.action_cant_be_completed, Toast.LENGTH_SHORT).show();
        Clog.w(Clog.baseLogTag, Clog.getString(R.string.adactivity_missing, activity_clz.getName()));
        BrowserAdActivity.BROWSER_QUEUE.remove();
    }
}

From source file:com.andrew.apollo.utils.ApolloUtils.java

/**
 * @param context The {@link Context} to use.
 * @return An {@link AlertDialog} used to show the open source licenses used
 *         in Apollo./*w w  w . j  a v a  2  s .  c o m*/
 */
public static final AlertDialog createOpenSourceDialog(final Context context) {
    final WebView webView = new WebView(context);
    webView.loadUrl("file:///android_asset/licenses.html");
    return new AlertDialog.Builder(context).setTitle(R.string.settings_open_source_licenses).setView(webView)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int whichButton) {
                    dialog.dismiss();
                }
            }).create();
}

From source file:Main.java

public static void runJavascriptOnWebView(WebView webview, String js) {
    // before Kitkat, the only way to run javascript was to load a url that starts with "javascript:".
    // Starting in Kitkat, the "javascript:" method still works, but it expects the rest of the string
    // to be URL encoded, unlike previous versions. Rather than URL encode for Kitkat and above,
    // use the new evaluateJavascript method.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        webview.loadUrl("javascript:" + js);
    } else {/*from   ww  w  .j a v a 2  s  .  co  m*/
        webview.evaluateJavascript(js, null);
    }
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callRecordEvent(AdWebView webView, Uri uri) {
    String urlParam = uri.getQueryParameter("url");

    if ((urlParam == null) || (!urlParam.startsWith("http"))) {
        return;// ww  w.  j av  a  2  s  .  c om
    }

    // Create a invisible webview to fire the url
    WebView recordEventWebView = new WebView(webView.getContext());
    recordEventWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            Clog.d(Clog.baseLogTag, "RecordEvent completed loading: " + url);

            CookieSyncManager csm = CookieSyncManager.getInstance();
            if (csm != null)
                csm.sync();
        }
    });
    recordEventWebView.loadUrl(urlParam);
    recordEventWebView.setVisibility(View.GONE);
    webView.addView(recordEventWebView);
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void loadResult(WebView webView, String cb, List<BasicNameValuePair> paramsList) {
    StringBuilder params = new StringBuilder();
    params.append("cb=").append(cb != null ? cb : "-1");
    if (paramsList != null) {
        for (BasicNameValuePair pair : paramsList) {
            if ((pair.getName() != null) && (pair.getValue() != null)) {
                params.append("&").append(pair.getName()).append("=").append(Uri.encode(pair.getValue()));
            }//  w ww  . j a  va  2s  . c  om
        }
    }
    String url = String.format("javascript:window.sdkjs.client.result(\"%s\")", params.toString());
    webView.loadUrl(url);
}

From source file:im.vector.util.VectorUtils.java

/**
 * Open a webview above the current activity.
 * @param activity the activity//w  w  w . jav  a 2 s.co m
 * @param url the url to open
 */
private static void displayInWebview(final Activity activity, String url) {
    AlertDialog.Builder alert = new AlertDialog.Builder(activity);

    WebView wv = new WebView(activity);
    wv.loadUrl(url);
    wv.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);

            return true;
        }
    });

    alert.setView(wv);
    alert.setPositiveButton(android.R.string.ok, null);
    alert.show();
}