List of usage examples for android.webkit WebView getUrl
@ViewDebug.ExportedProperty(category = "webview") public String getUrl()
From source file:org.mozilla.focus.webkit.FocusWebViewClient.java
@Override public void onPageFinished(WebView view, final String url) { if (callback != null) { callback.onPageFinished(view.getCertificate() != null); // The URL which is supplied in onPageFinished() could be fake (see #301), but webview's // URL is always correct _except_ for error pages final String viewURL = view.getUrl(); if (!UrlUtils.isInternalErrorURL(viewURL)) { callback.onURLChanged(view.getUrl()); }//from w w w .java 2 s.co m } super.onPageFinished(view, url); view.evaluateJavascript("(function() {" + CLEAR_VISITED_CSS + "})();", null); }
From source file:it.clipart.swipehtmlpageapp.IntroFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.intro_screen, container, false); View controlView = rootView.findViewById(R.id.introFinishControls); /*// w w w.j a v a2s .c o m If we are on the last page of the intro, we show a special controlView that lets the user select if they ever want to see this again, and continue on to the main part of the app. Se si nell'ultima pagina dell'intro, verr mostrato uno speciale controlView che lascia l'utente se vuole vederlo da capo o proseguire nella parte principale. */ if (item == MyWebActivity.NUM_INTRO_PAGES) { /* Se l'ultima pagina rende visibile il layout contenente il controllo che lancia la guida vera e propria - Il fatto che sia l'ultima pagina non viene creato un successivo Fragment e quindi lo swipe non pi attivo. */ controlView.setVisibility(View.VISIBLE); // Controlla la checkBox "Non mostrare pi" rootView.findViewById(R.id.checkBox).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dontShowAgainTapped(); } }); } // Se si torna indietro ( ad esempio ) rende invisibile il controllo di cui sopra else { controlView.setVisibility(View.INVISIBLE); } WebView webview = (WebView) rootView.findViewById(R.id.webView); android.webkit.WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webview.getSettings().setLoadsImagesAutomatically(true); webview.addJavascriptInterface(new WebAppInterface(this.activity), "Android"); webview.loadUrl("file:///android_asset/intro" + item + ".html"); Log.d(TAG, "Caricata la pagina intro url: " + webview.getUrl()); return rootView; }
From source file:com.robandjen.comicsapp.FullscreenActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }/*ww w . j a va2 s .co m*/ final int id = item.getItemId(); if (id == R.id.menu_reload) { onReload(); return true; } if (id == R.id.menu_cancel) { onCancel(); return true; } if (id == R.id.menu_browser) { WebView wv = (WebView) findViewById(R.id.fullscreen_content); String url = wv.getUrl(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } if (id == R.id.download) { URLFragment uf = URLFragment.newInstance(); uf.show(getFragmentManager(), "url"); return true; } if (id == R.id.cleardata) { deleteFile(COMICFILE); loadDefaultXML(); return true; } if (id == R.id.settings) { Intent intent = new Intent(getApplicationContext(), SettingsActivity.class); startActivity(intent); } return super.onOptionsItemSelected(item); }
From source file:com.robandjen.comicsapp.FullscreenActivity.java
@Override protected void onSaveInstanceState(Bundle bundle) { super.onSaveInstanceState(bundle); bundle.putInt(CURCOMICKEY, mCurComic); final WebView wv = (WebView) findViewById(R.id.fullscreen_content); if (wv != null) { bundle.putString(CURURLKEY, wv.getUrl()); }// w w w. j a v a 2s .c om }
From source file:no.digipost.android.gui.metadata.ExternalLinkWebview.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((DigipostApplication) getApplication()).getTracker(DigipostApplication.TrackerName.APP_TRACKER); setContentView(R.layout.activity_externallink_webview); Bundle bundle = getIntent().getExtras(); fileUrl = bundle.getString("url", "https://www.digipost.no"); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* w w w . ja v a 2s.c o m*/ actionBar = getSupportActionBar(); if (actionBar != null) { setActionBarTitle(fileUrl); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setBackgroundDrawable(new ColorDrawable(0xff2E2E2E)); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = this.getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor( ContextCompat.getColor(this, R.color.metadata_externalbrowser_top_background)); } } progressSpinner = (ProgressBar) findViewById(R.id.externallink_spinner); webView = (WebView) findViewById(R.id.externallink_webview); WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.setDomStorageEnabled(true); settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setScrollbarFadingEnabled(true); enableCookies(webView); webView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (firstLoad) { progressSpinner.setVisibility(View.GONE); webView.setVisibility(View.VISIBLE); firstLoad = false; } setActionBarTitle(view.getUrl()); } }); webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(final String url, final String userAgent, final String content, final String mimeType, final long contentLength) { fileName = URLUtil.guessFileName(url, content, mimeType); fileUrl = url; onComplete = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { showDownloadSuccessDialog(context); } } }; registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); if (!mimeType.equals("text/html")) { if (FileUtilities.isStorageWriteAllowed(getApplicationContext())) { showDownloadDialog(userAgent, content, mimeType, contentLength); } else { showMissingPermissionsDialog(); } } } }); if (FileUtilities.isStorageWriteAllowed(this)) { webView.loadUrl(fileUrl); } else { showPermissionsDialog(); } }
From source file:com.lemon.lime.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getBatteryPercentage();//w w w .j a va 2s .co m setContentView(R.layout.activity_main); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); mWebView = (ObservableWebView) findViewById(R.id.activity_main_webview); mWebView.setScrollViewCallbacks(this); LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(R.layout.bar, null); getSupportActionBar().setCustomView(v); WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath()); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mWebView.reload(); } }); swipeLayout.setColorSchemeResources(R.color.lili, R.color.colorPrimary, R.color.red); window = getWindow(); favicon = (ImageView) findViewById(R.id.favicon); editurl = (EditText) findViewById(R.id.editurl); mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }); favicon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (lili == 5) { lilimode(); lili = 0; lilimode = true; } else { lili = lili + 1; } } }); editurl.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { if (event.getAction() == KeyEvent.ACTION_UP) { if (editurl.getText().toString().contains("file:///")) { filemgr(); } else if (editurl.getText().toString().contains("gaymode")) { gaymode(); } else if (editurl.getText().toString().contains("exitapp")) { finish(); } else if (editurl.getText().toString().contains("light")) { flash(); } if (isconnected()) { if (editurl.getText().toString().contains("http://") || editurl.getText().toString().contains("https://")) { mWebView.loadUrl(editurl.getText().toString()); } else if (editurl.getText().toString().contains(".com") || editurl.getText().toString().contains(".net") || editurl.getText().toString().contains(".org") || editurl.getText().toString().contains(".gov") || editurl.getText().toString().contains(".hu") || editurl.getText().toString().contains(".sk") || editurl.getText().toString().contains(".co.uk") || editurl.getText().toString().contains(".co.in") || editurl.getText().toString().contains(".cn") || editurl.getText().toString().contains(".it") || editurl.getText().toString().contains(".de") || editurl.getText().toString().contains(".aus") || editurl.getText().toString().contains(".hr") || editurl.getText().toString().contains(".cz") || editurl.getText().toString().contains(".xyz") || editurl.getText().toString().contains(".pl") || editurl.getText().toString().contains(".io")) { mWebView.loadUrl("http://" + editurl.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0); } else { mWebView.loadUrl("https://www.google.com/search?q=" + editurl.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0); } } return true; } return false; } return true; } }); // Enable Javascript WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setSupportMultipleWindows(true); if (isconnected()) { mWebView.loadUrl("http://google.com"); } else { final View coordinatorLayoutView = findViewById(R.id.snackbarPosition); mWebView.loadUrl("file:///android_asset/nonet.html"); Snackbar snackbar = Snackbar.make(coordinatorLayoutView, R.string.offline, Snackbar.LENGTH_LONG); snackbar.show(); } mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onReceivedIcon(WebView mWebView, Bitmap icon) { super.onReceivedIcon(mWebView, icon); favicon.setImageBitmap(icon); } public void onProgressChanged(WebView view, int progress) { activity.setProgress(progress * 100); int a = progress; if (lilimode) { editurl.setText("Liling: " + Integer.toString(a) + "?"); } else editurl.setText("Liming: " + Integer.toString(a) + "%"); if (progress == 100) { editurl.setHint(view.getTitle()); activity.setTitle(view.getTitle()); editurl.setText(view.getUrl()); fav(); //battery if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (level <= 20) { window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setNavigationBarColor(Color.RED); window.setStatusBarColor(Color.RED); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.RED)); } } } } }); mWebView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView mWebView, String url) { swipeLayout.setRefreshing(false); } }); }
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 w w w .jav a 2 s. c o 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); }
From source file:com.baidu.cafe.local.record.WebElementRecorder.java
/** * set hook listener on WebView body//from www. j a v a 2s . c o m * * @param webView * @return */ public void handleWebView(final WebView webView) { if (webView == null) { return; } print("start monitor WebView: " + webView); webView.post(new Runnable() { public void run() { print("webView getURL: " + webView.getUrl()); } }); this.webView = webView; // monitor WebView hookWebView(webView); handleWebElementRecordEventQueue(); }
From source file:com.danielme.android.webviewdemo.WebViewDemoActivity.java
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) @Override/*from w w w .ja v a 2 s. co m*/ public void onCreate(Bundle savedInstanceState) { setTitle("?"); AndroidUtil.removeStrict(); super.onCreate(savedInstanceState); setContentView(R.layout.main); historyStack = new LinkedList<Link>(); webview = (WebView) findViewById(R.id.webkit); faviconImageView = (ImageView) findViewById(R.id.favicon); urlEditText = (EditText) findViewById(R.id.url); progressBar = (ProgressBar) findViewById(R.id.progressbar); stopButton = ((Button) findViewById(R.id.stopButton)); //favicon, deprecated since Android 4.3 but it's still necesary O_O ? WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath()); freeQuotaSwitch = (Switch) findViewById(R.id.freeQuotaSwitch); leftQuotaText = (TextView) findViewById(R.id.leftQuota); SharedPreferences settings = getSharedPreferences("setting", 0); userid = settings.getString("userid", "123"); tenantid = Integer.parseInt(settings.getString("tenantid", "3")); // check balance long balance = updateLeftQuota(); freeQuotaSwitch.setChecked(balance > 0); tmMgr = new TMManager(); // javascript and zoom webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { webview.getSettings().setPluginState(PluginState.ON); } else { //IMPORTANT!! this method is no longer available since Android 4.3 //so the code doesn't compile anymore //webview.getSettings().setPluginsEnabled(true); } // downloads // webview.setDownloadListener(new CustomDownloadListener()); webview.setWebViewClient(new CustomWebViewClient()); webview.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { progressBar.setProgress(0); FrameLayout progressBarLayout = (FrameLayout) findViewById(R.id.progressBarLayout); progressBarLayout.setVisibility(View.VISIBLE); WebViewDemoActivity.this.setProgress(progress * 1000); TextView progressStatus = (TextView) findViewById(R.id.progressStatus); progressStatus.setText(progress + " %"); progressBar.incrementProgressBy(progress); if (progress == 100) { progressBarLayout.setVisibility(View.GONE); } } @Override public void onReceivedTitle(WebView view, String title) { WebViewDemoActivity.this.setTitle( getString(R.string.app_name) + " - " + WebViewDemoActivity.this.webview.getTitle()); for (Link link : historyStack) { if (link.getUrl().equals(WebViewDemoActivity.this.webview.getUrl())) { link.setTitle(title); } } } @Override public void onReceivedIcon(WebView view, Bitmap icon) { faviconImageView.setImageBitmap(icon); view.getUrl(); boolean b = false; ListIterator<Link> listIterator = historyStack.listIterator(); while (!b && listIterator.hasNext()) { Link link = listIterator.next(); if (link.getUrl().equals(view.getUrl())) { link.setFavicon(icon); b = true; } } } }); //http://stackoverflow.com/questions/2083909/android-webview-refusing-user-input webview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); }
From source file:com.wellsandwhistles.android.redditsp.fragments.WebViewFragment.java
@SuppressLint("NewApi") @Override/*from w w w .j a v a 2s . co m*/ public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { mActivity = (AppCompatActivity) getActivity(); CookieSyncManager.createInstance(mActivity); outer = (FrameLayout) inflater.inflate(R.layout.web_view_fragment, null); webView = (WebViewFixed) outer.findViewById(R.id.web_view_fragment_webviewfixed); final FrameLayout loadingViewFrame = (FrameLayout) outer .findViewById(R.id.web_view_fragment_loadingview_frame); /*handle download links show an alert box to load this outside the internal browser*/ webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(final String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { { new AlertDialog.Builder(mActivity).setTitle(R.string.download_link_title) .setMessage(R.string.download_link_message) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); getContext().startActivity(i); mActivity.onBackPressed(); //get back from internal browser } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mActivity.onBackPressed(); //get back from internal browser } }).setIcon(android.R.drawable.ic_dialog_alert).show(); } } }); /*handle download links end*/ progressView = new ProgressBar(mActivity, null, android.R.attr.progressBarStyleHorizontal); loadingViewFrame.addView(progressView); loadingViewFrame.setPadding(General.dpToPixels(mActivity, 10), 0, General.dpToPixels(mActivity, 10), 0); final WebSettings settings = webView.getSettings(); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(false); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setDomStorageEnabled(true); settings.setDisplayZoomControls(false); // TODO handle long clicks webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, final int newProgress) { super.onProgressChanged(view, newProgress); General.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { progressView.setProgress(newProgress); progressView.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE); } }); } }); if (mUrl != null) { webView.loadUrl(mUrl); } else { webView.loadDataWithBaseURL("https://reddit.com/", html, "text/html; charset=UTF-8", null, null); } webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(final WebView view, final String url) { if (url == null) return false; if (url.startsWith("data:")) { // Prevent imgur bug where we're directed to some random data URI return true; } // Go back if loading same page to prevent redirect loops. if (goingBack && currentUrl != null && url.equals(currentUrl)) { General.quickToast(mActivity, String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt), Toast.LENGTH_SHORT); lastBackDepthAttempt--; if (webView.canGoBackOrForward(lastBackDepthAttempt)) { webView.goBackOrForward(lastBackDepthAttempt); } else { mActivity.finish(); } } else { if (RedditURLParser.parse(Uri.parse(url)) != null) { LinkHandler.onLinkClicked(mActivity, url, false); } else { webView.loadUrl(url); currentUrl = url; } } return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (mUrl != null && url != null) { final AppCompatActivity activity = mActivity; if (activity != null) { activity.setTitle(url); } } } @Override public void onPageFinished(final WebView view, final String url) { super.onPageFinished(view, url); new Timer().schedule(new TimerTask() { @Override public void run() { General.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { if (currentUrl == null || url == null) return; if (!url.equals(view.getUrl())) return; if (goingBack && url.equals(currentUrl)) { General.quickToast(mActivity, String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt)); lastBackDepthAttempt--; if (webView.canGoBackOrForward(lastBackDepthAttempt)) { webView.goBackOrForward(lastBackDepthAttempt); } else { mActivity.finish(); } } else { goingBack = false; } } }); } }, 1000); } @Override public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) { super.doUpdateVisitedHistory(view, url, isReload); } }); final FrameLayout outerFrame = new FrameLayout(mActivity); outerFrame.addView(outer); return outerFrame; }