List of usage examples for android.webkit WebView loadUrl
public void loadUrl(String url)
From source file:org.geometerplus.android.fbreader.network.auth.WebAuthorisationScreen.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_PROGRESS); SQLiteCookieDatabase.init(this); CookieSyncManager.createInstance(getApplicationContext()); CookieManager.getInstance().removeAllCookie(); final Intent intent = getIntent(); final Uri data = intent.getData(); if (data == null || data.getHost() == null) { finish();/* w ww. ja v a 2s . c o m*/ return; } final String completeUrl = intent.getStringExtra(COMPLETE_URL_KEY); OrientationUtil.setOrientation(this, intent); final WebView view = new WebView(this); view.getSettings().setJavaScriptEnabled(true); view.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { setProgress(progress * 100); } }); view.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { setTitle(url); if (url != null && url.startsWith(completeUrl)) { final HashMap<String, String> cookies = new HashMap<String, String>(); final String cookieString = CookieManager.getInstance().getCookie(url); if (cookieString != null) { // cookieString is a string like NAME=VALUE [; NAME=VALUE] for (String pair : cookieString.split(";")) { final String[] parts = pair.split("=", 2); if (parts.length != 2) { continue; } cookies.put(parts[0].trim(), parts[1].trim()); } } storeCookies(data.getHost(), cookies); WebAuthorisationScreen.this.setResult(RESULT_OK); finish(); } } public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ECLAIR_MR1) { // hack for auth problem in android 2.1 handler.proceed(); } else { super.onReceivedSslError(view, handler, error); } } }); setContentView(view); view.loadUrl(intent.getDataString()); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Opens a url in an alert dialog./*from w w w .j a v a 2 s . c om*/ * * @param context * @param title * @param url */ public static void dialog_showUrlInDialog(Context context, String title, String url) { AlertDialog.Builder alert = new AlertDialog.Builder(context); alert.setTitle(title); WebView wv = new WebView(context); wv.loadUrl(url); wv.setHorizontalScrollBarEnabled(false); alert.setView(wv); alert.setNegativeButton("Close", null); alert.show(); }
From source file:com.owncloud.android.ui.activity.ExternalSiteWebView.java
@Override protected void onCreate(Bundle savedInstanceState) { Log_OC.v(TAG, "onCreate() start"); Bundle extras = getIntent().getExtras(); String title = extras.getString(EXTRA_TITLE); String url = extras.getString(EXTRA_URL); menuItemId = extras.getInt(EXTRA_MENU_ITEM_ID); showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR); // show progress getWindow().requestFeature(Window.FEATURE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.externalsite_webview); WebView webview = (WebView) findViewById(R.id.webView); WebSettings webSettings = webview.getSettings(); webview.setFocusable(true);// w w w. j a v a 2s . com webview.setFocusableInTouchMode(true); webview.setClickable(true); // setup toolbar setupToolbar(); // setup drawer setupDrawer(menuItemId); if (!showSidebar) { setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } getSupportActionBar().setTitle(title); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // enable zoom webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); // Non-responsive webs are zoomed out when loaded webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); // user agent webSettings.setUserAgentString(MainApp.getUserAgent()); // no private data storing webSettings.setSavePassword(false); webSettings.setSaveFormData(false); // disable local file access webSettings.setAllowFileAccess(false); // enable javascript webview.getSettings().setJavaScriptEnabled(true); final Activity activity = this; final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar); webview.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { progressBar.setProgress(progress * 1000); } }); webview.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Toast.makeText(activity, getString(R.string.webview_error) + ": " + description, Toast.LENGTH_SHORT) .show(); } }); webview.loadUrl(url); }
From source file:com.google.android.apps.paco.FeedbackActivity.java
private WebViewClient createWebViewClientThatHandlesFileLinksForCharts(final Feedback feedback) { WebViewClient webViewClient = new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri uri = Uri.parse(url);// ww w.j ava 2 s . c o m if (uri.getScheme().startsWith("http")) { return true; // throw away http requests - we don't want 3rd party javascript sending url requests due to security issues. } String inputIdStr = uri.getQueryParameter("inputId"); if (inputIdStr == null) { return true; } long inputId = Long.parseLong(inputIdStr); JSONArray results = new JSONArray(); for (Event event : experiment.getEvents()) { JSONArray eventJson = new JSONArray(); DateTime responseTime = event.getResponseTime(); if (responseTime == null) { continue; // missed signal; } eventJson.put(responseTime.getMillis()); // in this case we are looking for one input from the responses that we are charting. for (Output response : event.getResponses()) { if (response.getInputServerId() == inputId) { Input inputById = experiment.getInputById(inputId); if (!inputById.isInvisible() && inputById.isNumeric()) { eventJson.put(response.getDisplayOfAnswer(inputById)); results.put(eventJson); continue; } } } } env.put("data", results.toString()); env.put("inputId", inputIdStr); view.loadUrl(stripQuery(url)); return true; } }; return webViewClient; }
From source file:tv.acfun.a63.ArticleActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override/* w ww. j a va2s .c o m*/ protected void initView(Bundle savedInstanceState) { ARTICLE_PATH = AcApp.getExternalCacheDir("article").getAbsolutePath(); Uri data = getIntent().getData(); if (Intent.ACTION_VIEW.equalsIgnoreCase(getIntent().getAction()) && data != null) { String scheme = data.getScheme(); if (scheme.equals("ac")) { // ac://ac000000 aid = Integer.parseInt(getIntent().getDataString().substring(7)); } else if (scheme.equals("http")) { // http://www.acfun.tv/v/ac123456 Matcher matcher; String path = data.getPath(); if (path == null) { finish(); return; } if ((matcher = sVreg.matcher(path)).find() || (matcher = sAreg.matcher(path)).find()) { aid = Integer.parseInt(matcher.group(1)); } } if (aid != 0) title = "ac" + aid; isWebMode = getIntent().getBooleanExtra("webmode", false) && aid == 0; } else { aid = getIntent().getIntExtra("aid", 0); title = getIntent().getStringExtra("title"); } if (!isWebMode) { if (aid == 0) throw new IllegalArgumentException(" id"); getSupportActionBar().setTitle("ac" + aid); MobclickAgent.onEvent(this, "view_article"); db = new DB(this); isFaved = db.isFav(aid); } mWeb.getSettings().setAppCachePath(ARTICLE_PATH); mWeb.addJavascriptInterface(new ACJSObject(), "AC"); // Set a chrome client to handle the MediaResource on web page // like video,video loading progress, etc. mWeb.setWebChromeClient(new WebChromeClient() { @Override public void onReceivedTitle(WebView view, String title) { setTitle(title); } }); mWeb.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Matcher matcher = sAreg.matcher(url); Intent intent = new Intent(Intent.ACTION_VIEW); if (matcher.find() || (matcher = sLiteAreg.matcher(url)).find() || (matcher = sVreg.matcher(url)).find() || (matcher = sLiteVreg.matcher(url)).find()) { String acId = matcher.group(1); try { intent.setData(Uri.parse("ac://ac" + acId)); startActivity(intent); return true; } catch (Exception e) { // nothing } } else if (Pattern.matches(sAppReg, url)) { String appLink = getString(R.string.app_ac_video_link); try { intent.setData(Uri.parse(appLink)); startActivity(intent); return true; } catch (Exception e) { view.loadUrl(appLink); return true; } } if (!isWebMode) { start(ArticleActivity.this, url); return true; } else { Uri uri = Uri.parse(url); if (uri.getHost() != null && !uri.getHost().contains("acfun")) { try { intent.setData(uri); startActivity(intent); return true; } catch (ActivityNotFoundException ignored) { } } } return false; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { setSupportProgressBarIndeterminateVisibility(true); } @Override public void onPageFinished(WebView view, String url) { setSupportProgressBarIndeterminateVisibility(false); if (isWebMode || imgUrls == null || imgUrls.isEmpty() || url.startsWith("file:///android_asset") || AcApp.getViewMode() == Constants.MODE_NO_PIC) // ? return; // Log.d(TAG, "on finished:" + url); if ((url.equals(getBaseUrl()) || url.contains(NAME_ARTICLE_HTML)) && imgUrls.size() > 0 && !isDownloaded) { String[] arr = new String[imgUrls.size()]; mDownloadTask = new DownloadImageTask(); mDownloadTask.execute(imgUrls.toArray(arr)); } } }); mWeb.getSettings().setSupportZoom(true); mWeb.getSettings().setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) mWeb.getSettings().setDisplayZoomControls(false); setTextZoom(AcApp.getConfig().getInt("text_size", 0)); }
From source file:de.baumann.browser.helper.helper_webView.java
public static void webView_WebViewClient(final Activity from, final SwipeRefreshLayout swipeRefreshLayout, final WebView webView, final EditText editText) { webView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); swipeRefreshLayout.setRefreshing(false); editText.setText(webView.getTitle()); if (webView.getTitle() != null && !webView.getTitle().equals("about:blank")) { try { final Database_History db = new Database_History(from); db.addBookmark(webView.getTitle(), webView.getUrl()); db.close();//from w ww .java 2 s.co m } catch (Exception e) { e.printStackTrace(); } } } @SuppressWarnings("deprecation") @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { final Uri uri = Uri.parse(url); return handleUri(uri); } @TargetApi(Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final Uri uri = request.getUrl(); return handleUri(uri); } private boolean handleUri(final Uri uri) { Log.i(TAG, "Uri =" + uri); final String url = uri.toString(); // Based on some condition you need to determine if you are going to load the url // in your web view itself or in a browser. // You can use `host` or `scheme` or any part of the `uri` to decide. if (url.startsWith("http")) return false;//open web links as usual //try to find browse activity to handle uri Uri parsedUri = Uri.parse(url); PackageManager packageManager = from.getPackageManager(); Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri); if (browseIntent.resolveActivity(packageManager) != null) { from.startActivity(browseIntent); return true; } //if not activity found, try to parse intent:// if (url.startsWith("intent:")) { try { Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); if (intent.resolveActivity(from.getPackageManager()) != null) { from.startActivity(intent); return true; } //try to find fallback url String fallbackUrl = intent.getStringExtra("browser_fallback_url"); if (fallbackUrl != null) { webView.loadUrl(fallbackUrl); return true; } //invite to install Intent marketIntent = new Intent(Intent.ACTION_VIEW) .setData(Uri.parse("market://details?id=" + intent.getPackage())); if (marketIntent.resolveActivity(packageManager) != null) { from.startActivity(marketIntent); return true; } } catch (URISyntaxException e) { //not an intent uri } } return true;//do nothing in other cases } }); }
From source file:app.clirnet.com.clirnetapp.activity.LoginActivity.java
private void showDialog12() { final View checkBoxView = View.inflate(this, R.layout.alert_checkbox, null); final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkBox); final WebView wv = (WebView) checkBoxView.findViewById(R.id.webview); // checkBox.setText("Yes, I accept the terms and condition"); final AlertDialog.Builder ad = new AlertDialog.Builder(this) // .setMessage(termsnconditiomessage) .setView(checkBoxView).setIcon(R.drawable.info).setTitle("Terms of Service"); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override// ww w. java2 s . c o m public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { //Method will send radio button checked status to yes button for further process of redirection checkedStatus(true); } else { checkedStatus(false); Toast.makeText(getApplicationContext(), "Please accept the terms and condition to proceed ", Toast.LENGTH_LONG).show(); } } }); wv.setVisibility(View.VISIBLE); wv.loadUrl("http://doctor.clirnet.com/doctor/patientcentral/termsandcondition"); wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); ad.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //Toast.makeText(mContext.getApplicationContext(), "You have accepted the TOS. Welcom to the site", Toast.LENGTH_SHORT).show(); if (responceCheck) { rememberTermsCondition("Yes"); Intent intent = new Intent(getApplicationContext(), SplashActivity.class); startActivity(intent); new AppController().showToastMsg(getApplicationContext(), "Login Successful"); startService(); } else { new AppController().showToastMsg(getApplicationContext(), "Please accept the terms and condition to proceed"); // Toast.makeText(mContext.getApplicationContext(), "Please accept the terms and condition to proceed", Toast.LENGTH_SHORT).show(); } } }); ad.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "You have denied the TOS. You may not access the site", Toast.LENGTH_SHORT).show(); rememberTermsCondition("No"); } }); ad.setNeutralButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "Please select yes or no", Toast.LENGTH_SHORT).show(); rememberTermsCondition("No"); } }); ad.setCancelable(false); ad.setView(checkBoxView); ad.show(); }
From source file:org.sufficientlysecure.keychain.ui.linked.LinkedIdCreateGithubFragment.java
public void oAuthRequest(String hostAndPath, String clientId, String scope) { Activity activity = getActivity();/*from w ww.ja va 2 s . c o m*/ if (activity == null) { return; } byte[] buf = new byte[16]; new Random().nextBytes(buf); mOAuthState = new String(Hex.encode(buf)); mOAuthCode = null; final Dialog auth_dialog = new Dialog(activity); auth_dialog.setContentView(R.layout.oauth_webview); WebView web = (WebView) auth_dialog.findViewById(R.id.web_view); web.getSettings().setSaveFormData(false); web.getSettings().setUserAgentString("OpenKeychain " + BuildConfig.VERSION_NAME); web.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri uri = Uri.parse(url); if ("oauth-openkeychain".equals(uri.getScheme())) { if (mOAuthCode != null) { return true; } if (uri.getQueryParameter("error") != null) { Log.i(Constants.TAG, "got oauth error: " + uri.getQueryParameter("error")); auth_dialog.dismiss(); return true; } // check if mOAuthState == queryParam[state] mOAuthCode = uri.getQueryParameter("code"); auth_dialog.dismiss(); return true; } // don't surf away from github! if (!"github.com".equals(uri.getHost())) { auth_dialog.dismiss(); return true; } return false; } }); auth_dialog.setTitle(R.string.linked_webview_title_github); auth_dialog.setCancelable(true); auth_dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { step1GetOAuthToken(); } }); auth_dialog.show(); web.loadUrl("https://" + hostAndPath + "?client_id=" + clientId + "&scope=" + scope + "&redirect_uri=oauth-openkeychain://linked/" + "&state=" + mOAuthState); }
From source file:nya.miku.wishmaster.http.cloudflare.CloudflareChecker.java
private Cookie checkAntiDDOS(final CloudflareException exception, final HttpHost proxy, CancellableTask task, final Activity activity) { synchronized (lock) { if (processing) return null; processing = true;/*from w ww .j a v a 2s . c o m*/ } processing2 = true; currentCookie = null; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { CookieSyncManager.createInstance(activity); CookieManager.getInstance().removeAllCookie(); } else { CompatibilityImpl.clearCookies(CookieManager.getInstance()); } final ViewGroup layout = (ViewGroup) activity.getWindow().getDecorView().getRootView(); final WebViewClient client = new WebViewClient() { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); } @Override public void onPageFinished(WebView webView, String url) { super.onPageFinished(webView, url); Logger.d(TAG, "Got Page: " + url); String value = null; try { String[] cookies = CookieManager.getInstance().getCookie(url).split("[;]"); for (String cookie : cookies) { if ((cookie != null) && (!cookie.trim().equals("")) && (cookie.startsWith(" " + exception.getRequiredCookieName() + "="))) { value = cookie.substring(exception.getRequiredCookieName().length() + 2); } } } catch (NullPointerException e) { Logger.e(TAG, e); } if (value != null) { BasicClientCookieHC4 cf_cookie = new BasicClientCookieHC4(exception.getRequiredCookieName(), value); cf_cookie.setDomain("." + Uri.parse(url).getHost()); cf_cookie.setPath("/"); currentCookie = cf_cookie; Logger.d(TAG, "Cookie found: " + value); processing2 = false; } else { Logger.d(TAG, "Cookie is not found"); } } }; activity.runOnUiThread(new Runnable() { @SuppressLint("SetJavaScriptEnabled") @Override public void run() { webView = new WebView(activity); webView.setVisibility(View.GONE); layout.addView(webView); webView.setWebViewClient(client); webView.getSettings().setUserAgentString(HttpConstants.USER_AGENT_STRING); webView.getSettings().setJavaScriptEnabled(true); webViewContext = webView.getContext(); if (proxy != null) WebViewProxy.setProxy(webViewContext, proxy.getHostName(), proxy.getPort()); webView.loadUrl(exception.getCheckUrl()); } }); long startTime = System.currentTimeMillis(); while (processing2) { long time = System.currentTimeMillis() - startTime; if ((task != null && task.isCancelled()) || time > TIMEOUT) { processing2 = false; } } activity.runOnUiThread(new Runnable() { @Override public void run() { try { layout.removeView(webView); webView.stopLoading(); webView.clearCache(true); webView.destroy(); webView = null; } finally { if (proxy != null) WebViewProxy.setProxy(webViewContext, null, 0); processing = false; } } }); return currentCookie; }
From source file:de.baumann.hhsmoodle.helper.helper_webView.java
public static void webView_WebViewClient(final Activity from, final SwipeRefreshLayout swipeRefreshLayout, final WebView webView) { webView.setWebViewClient(new WebViewClient() { ProgressDialog progressDialog;/*from w w w . j ava 2s . c o m*/ int numb; public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); ViewPager viewPager = (ViewPager) from.findViewById(R.id.viewpager); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from); sharedPref.edit().putString("loadURL", webView.getUrl()).apply(); if (viewPager.getCurrentItem() == 0) { if (url != null) { from.setTitle(webView.getTitle()); } } if (url != null && url.contains("moodle.huebsch.ka.schule-bw.de/moodle/") && url.contains("/login/")) { if (viewPager.getCurrentItem() == 0 && numb != 1) { progressDialog = new ProgressDialog(from); progressDialog.setTitle(from.getString(R.string.login_title)); progressDialog.setMessage(from.getString(R.string.login_text)); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, from.getString(R.string.toast_settings), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { helper_main.switchToActivity(from, Activity_settings.class, true); } }); progressDialog.show(); numb = 1; progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { numb = 0; } }); } } else if (progressDialog != null && progressDialog.isShowing()) { progressDialog.cancel(); numb = 0; } swipeRefreshLayout.setRefreshing(false); class_SecurePreferences sharedPrefSec = new class_SecurePreferences(from, "sharedPrefSec", "Ywn-YM.XK$b:/:&CsL8;=L,y4", true); String username = sharedPrefSec.getString("username"); String password = sharedPrefSec.getString("password"); final String js = "javascript:" + "document.getElementById('password').value = '" + password + "';" + "document.getElementById('username').value = '" + username + "';" + "var ans = document.getElementsByName('answer');" + "document.getElementById('loginbtn').click()"; if (Build.VERSION.SDK_INT >= 19) { view.evaluateJavascript(js, new ValueCallback<String>() { @Override public void onReceiveValue(String s) { } }); } else { view.loadUrl(js); } } @SuppressWarnings("deprecation") @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { final Uri uri = Uri.parse(url); return handleUri(uri); } @TargetApi(Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final Uri uri = request.getUrl(); return handleUri(uri); } private boolean handleUri(final Uri uri) { Log.i(TAG, "Uri =" + uri); final String url = uri.toString(); // Based on some condition you need to determine if you are going to load the url // in your web view itself or in a browser. // You can use `host` or `scheme` or any part of the `uri` to decide. if (url.startsWith("http")) return false;//open web links as usual //try to find browse activity to handle uri Uri parsedUri = Uri.parse(url); PackageManager packageManager = from.getPackageManager(); Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri); if (browseIntent.resolveActivity(packageManager) != null) { from.startActivity(browseIntent); return true; } //if not activity found, try to parse intent:// if (url.startsWith("intent:")) { try { Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); if (intent.resolveActivity(from.getPackageManager()) != null) { from.startActivity(intent); return true; } //try to find fallback url String fallbackUrl = intent.getStringExtra("browser_fallback_url"); if (fallbackUrl != null) { webView.loadUrl(fallbackUrl); return true; } //invite to install Intent marketIntent = new Intent(Intent.ACTION_VIEW) .setData(Uri.parse("market://details?id=" + intent.getPackage())); if (marketIntent.resolveActivity(packageManager) != null) { from.startActivity(marketIntent); return true; } } catch (URISyntaxException e) { //not an intent uri } } return true;//do nothing in other cases } }); }