List of usage examples for android.webkit WebView loadUrl
public void loadUrl(String url)
From source file:com.purchasingpower.inappbrowser.WebViewActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); setContentView(getResources().getIdentifier("nativebrowserplugin", "layout", getPackageName())); if (!checkPermission()) { requestPermission();/*from w ww. ja va 2s. c o m*/ } Intent intent = getIntent(); String url = intent.getExtras().getString("url"); final WebView myWebView = (WebView) findViewById( getResources().getIdentifier("webview", "id", getPackageName())); myWebView.setWebViewClient(new MyWebViewClient()); webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setLoadWithOverviewMode(true); webSettings.setAllowFileAccess(true); myWebView.setWebChromeClient(new PQChromeClient()); //if SDK version is greater of 19 then activate hardware acceleration otherwise activate software acceleration if (Build.VERSION.SDK_INT >= 19) { myWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } else if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 19) { myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } myWebView.loadUrl(url); back = (ImageView) findViewById(getResources().getIdentifier("back", "id", getPackageName())); back.setImageResource(getResources().getIdentifier("back_gray", "drawable", getPackageName())); forward = (ImageView) findViewById(getResources().getIdentifier("forward", "id", getPackageName())); forward.setImageResource(getResources().getIdentifier("forward_gray", "drawable", getPackageName())); done = (TextView) findViewById(getResources().getIdentifier("done", "id", getPackageName())); pbar = (ProgressBar) findViewById(getResources().getIdentifier("pbar", "id", getPackageName())); pbar.setVisibility(View.VISIBLE); back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (myWebView.canGoBack()) { myWebView.goBack(); } } }); forward.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (myWebView.canGoForward()) { myWebView.goForward(); } } }); done.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.v("Done", "Clicked"); finish(); } }); }
From source file:com.scm.reader.resultPage.webview.ShortcutWebViewClient.java
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) { JSONObject json = new JSONObject(); JSONObject appInfo = new JSONObject(); JSONObject supportedActions = new JSONObject(); try {/* w w w .j a va2 s.co m*/ json.put("appInfo", appInfo); appInfo.put("systemName", "Android"); Log.d("WEB", "onPageStarted"); appInfo.put("name", SDKConfig.SDK_UA_NAME); Iterator it = getWebViewCapabilities().entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Boolean> capability = (Map.Entry) it.next(); appInfo.put(capability.getKey(), capability.getValue()); } appInfo.put("version", SDKConfig.SDK_VERSION_CODE); appInfo.put("systemVersion", Build.VERSION.RELEASE); // appInfo.put("userIsSignedIn", loggedIn()); appInfo.put("userIsSignedIn", false); supportedActions.put("openUrlInBrowser", true); supportedActions.put("openImageOrPDF", true); appInfo.put("supportedActions", supportedActions); view.loadUrl("javascript:window.kooaba = eval(" + json.toString(0) + ");"); } catch (JSONException e) { LOGE(TAG, "Could not construct JSON object with app info", e); } super.onPageStarted(view, url, favicon); }
From source file:info.alni.comete.android.Comete.java
private AlertDialog createHelpDialog() { final WebView wv = new WebView(this); wv.setTag("help"); wv.getSettings().setJavaScriptEnabled(true); wv.setWebViewClient(internalWebViewClient); wv.loadUrl(URL_HELP_MAIN); return new AlertDialog.Builder(this).setTitle("Help").setView(wv) .setPositiveButton("Close", new DialogInterface.OnClickListener() { @Override/*w ww.ja v a 2 s .c o m*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); }
From source file:com.linkbubble.util.PageInspector.java
public void run(WebView webView, String adInsert) { mWebViewUrl = webView.getUrl();/*from w ww. ja v a 2 s .c o m*/ if (mScriptCache == null) { mScriptCache = "javascript:(function() {\n"; if (MainController.get() == null || !MainController.get().hasStableWebViewForSelects(mContext)) { mScriptCache += getFileContents("SelectElements"); } mScriptCache += getFileContents("TouchIcon"); mScriptCache += getFileContents("YouTube"); mScriptCache += getFileContents("FetchContent"); mScriptCache += getFileContents("ThemeColor"); mScriptCache += getFileContents("HideBrokenImages"); } String scriptToExecute = mScriptCache; if (null != adInsert && !adInsert.equals("")) { scriptToExecute += "\nvar adInfoObject = " + adInsert + ";\n"; scriptToExecute += getFileContents("AddInsertion"); } scriptToExecute += "}());"; webView.loadUrl(scriptToExecute); }
From source file:com.example.prasadnr.traquad.TraQuad.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tra_quad); ConnectivityManager connManager = (ConnectivityManager) getSystemService(TraQuad.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); Builder alert = new AlertDialog.Builder(TraQuad.this); WifiManager managerWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); Method[] wmMethods = managerWifi.getClass().getDeclaredMethods(); for (Method method : wmMethods) { if (method.getName().equals("isWifiApEnabled")) { try { isWifiAPenabled = (boolean) method.invoke(managerWifi); } catch (IllegalArgumentException e) { e.printStackTrace();/*from w w w .j a va 2s . co m*/ } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } final ProgressDialog pDialog; MediaController mediaController = new MediaController(this); pDialog = new ProgressDialog(TraQuad.this); pDialog.setTitle("TraQuad app (Connecting...)"); pDialog.setMessage("Buffering...Please wait..."); pDialog.setCancelable(true); if (!isWifiAPenabled) { alert.setTitle("WiFi Hotspot Settings"); alert.setMessage("Can you please connect WiFi-hotspot?"); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { irritation = true; startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); pDialog.show(); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //Dismiss AlertDialog pDialog.show(); Toast.makeText(getApplicationContext(), "Please connect your WiFi!", Toast.LENGTH_LONG).show(); } }); alert.setCancelable(false); AlertDialog alertDialog = alert.create(); alertDialog.show(); } WebView webView = (WebView) findViewById(R.id.webView); if (irritation == true | isWifiAPenabled) { pDialog.show(); } mediaController.setAnchorView(webView); mediaController.setVisibility(View.GONE); extra = getIntent().getStringExtra("VideosId"); webView = (WebView) findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setPluginState(WebSettings.PluginState.ON); final GlobalClass globalVariable = (GlobalClass) getApplicationContext(); final String IPaddressNew = globalVariable.getIP(); final String httpString = "http://"; final String commandPort = String.valueOf(1500); final String streamPort = String.valueOf(8080); final String IPaddressStream = httpString + IPaddressNew + ":" + streamPort; final String IPaddressCommand = httpString + IPaddressNew + ":" + commandPort; TextView sendCharacter = (TextView) findViewById(R.id.sendCharacter); try { webView.loadUrl(IPaddressStream); } catch (Exception e) { Toast.makeText(getApplicationContext(), IPaddressNew + ":Error!", Toast.LENGTH_LONG).show(); } webView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { pDialog.dismiss(); } }); final Button switchact = (Button) findViewById(R.id.btn2); switchact.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent act1 = new Intent(view.getContext(), Joypad.class); startActivity(act1); } }); final Button hometraquad = (Button) findViewById(R.id.button5); hometraquad.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent acthometraquad = new Intent(TraQuad.this, MainActivity.class); startActivity(acthometraquad); } }); }
From source file:com.baidu.cafe.local.record.WebElementRecorder.java
/** * @param webView//from w ww. j a v a 2 s . c o m * @param javaScript */ public void hookWebElements(final WebView webView, final String javaScript) { webView.post(new Runnable() { public void run() { if (webView != null) { webView.loadUrl("javascript:" + javaScript); } } }); // viewRecorder.getLocalLib().getCurrentActivity().setProgress(10000); }
From source file:com.facebook.react.views.webview.ReactWebViewManager.java
@Override public void receiveCommand(WebView root, int commandId, @Nullable ReadableArray args) { switch (commandId) { case COMMAND_GO_BACK: root.goBack();// www . j av a 2s.c o m break; case COMMAND_GO_FORWARD: root.goForward(); break; case COMMAND_RELOAD: root.reload(); break; case COMMAND_STOP_LOADING: root.stopLoading(); break; case COMMAND_POST_MESSAGE: try { JSONObject eventInitDict = new JSONObject(); eventInitDict.put("data", args.getString(0)); root.loadUrl("javascript:(function () {" + "var event;" + "var data = " + eventInitDict.toString() + ";" + "try {" + "event = new MessageEvent('message', data);" + "} catch (e) {" + "event = document.createEvent('MessageEvent');" + "event.initMessageEvent('message', true, true, data.data, data.origin, data.lastEventId, data.source);" + "}" + "document.dispatchEvent(event);" + "})();"); } catch (JSONException e) { throw new RuntimeException(e); } break; case COMMAND_INJECT_JAVASCRIPT: root.loadUrl("javascript:" + args.getString(0)); break; } }
From source file:de.mkrtchyan.recoverytools.RecoveryTools.java
private void showChangelog() { if (version_changed) { AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); dialog.setTitle(R.string.changelog); WebView changes = new WebView(mContext); changes.setWebViewClient(new WebViewClient()); changes.loadUrl("http://forum.xda-developers.com/showpost.php?p=42839595&postcount=3"); dialog.setView(changes);//from w w w .ja v a2 s . com dialog.show(); } }
From source file:com.anxpp.blog.fragment.AboutFragment.java
@SuppressLint("SetJavaScriptEnabled") private void initView() { webView = (WebView) getView().findViewById(R.id.webView); // webView.setVisibility(View.GONE); webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { Activity activity = getActivity(); /**/*from ww w.ja va 2s.co m*/ * ?Fragment??? * I am not sure why are you getting this error, * i think it should be something like NullPointerException. * Try next: * Evert time you calling getActivity() on Fragment instance you should be sure, * that fragment is actually have this Activity. * Because when your webview is loading you are calling this function: * */ if (activity == null) return; activity.setTitle("Loading..." + progress + "%"); activity.setProgress(progress * 100); if (progress == 100) { activity.setTitle(R.string.app_name); webView.setVisibility(View.VISIBLE); } } }); webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Toast("shouldOverrideUrlLoading"); view.loadUrl(url); return true; } }); //?? WebSettings webSettings = webView.getSettings(); //? //webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //?js webSettings.setJavaScriptEnabled(true); //? ? webSettings.setUseWideViewPort(false); //?? webSettings.setLoadWithOverviewMode(true); // ?? webView.loadUrl("http://anxpp.com"); // webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //trueWebViewfalse?? view.loadUrl(url); return true; //false? } }); webView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { // ? webView.goBack(); //? return true; //? } } return false; } }); }
From source file:com.openatk.fieldnotebook.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.main_menu_add) { addFieldMapView();//w w w .j a va 2 s .c om return true; } else if (item.getItemId() == R.id.main_menu_current_location) { Location myLoc = map.getMyLocation(); if (myLoc == null) { Toast.makeText(this, "Still searching for your location", Toast.LENGTH_SHORT).show(); } else { CameraPosition oldPos = map.getCameraPosition(); CameraPosition newPos = new CameraPosition(new LatLng(myLoc.getLatitude(), myLoc.getLongitude()), map.getMaxZoomLevel(), oldPos.tilt, oldPos.bearing); map.animateCamera(CameraUpdateFactory.newCameraPosition(newPos)); } return true; } else if (item.getItemId() == R.id.main_menu_list_view) { /*if(sliderIsShowing == 0){ showSlider(true); } else { hideSlider(true); } if (mCurrentState == STATE_LIST_VIEW) { // Show map view Log.d("MainActivity", "Showing map view"); setState(STATE_DEFAULT); //item.setIcon(R.drawable.list_view); } else { // Show list view Log.d("MainActivity", "Showing list view"); setState(STATE_LIST_VIEW); //item.setIcon(R.drawable.map_view); }*/ return true; } else if (item.getItemId() == R.id.main_menu_help) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Help"); WebView wv = new WebView(this); wv.loadUrl("file:///android_asset/Help.html"); wv.getSettings().setSupportZoom(true); wv.getSettings().setBuiltInZoomControls(true); wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); alert.setView(wv); alert.setNegativeButton("Close", null); alert.show(); return true; } else if (item.getItemId() == R.id.main_menu_legal) { CharSequence licence = "The MIT License (MIT)\n" + "\n" + "Copyright (c) 2013 Purdue University\n" + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy " + "of this software and associated documentation files (the \"Software\"), to deal " + "in the Software without restriction, including without limitation the rights " + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell " + "copies of the Software, and to permit persons to whom the Software is " + "furnished to do so, subject to the following conditions:" + "\n" + "The above copyright notice and this permission notice shall be included in " + "all copies or substantial portions of the Software.\n" + "\n" + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR " + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, " + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER " + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, " + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN " + "THE SOFTWARE.\n"; new AlertDialog.Builder(this).setTitle("Legal").setMessage(licence) .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton("Close", null).show(); return true; } return super.onOptionsItemSelected(item); }