List of usage examples for android.webkit ValueCallback ValueCallback
ValueCallback
From source file:Main.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void removeAllCookiesV21() { final CookieManager cookieManager = CookieManager.getInstance(); Looper looper = Looper.myLooper();//from w w w . ja va2 s .c o m boolean prepared = false; if (looper == null) { Looper.prepare(); prepared = true; } // requires a looper cookieManager.removeAllCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { Thread thread = new Thread() { @Override public void run() { // is synchronous, run in background cookieManager.flush(); } }; thread.start(); } }); if (prepared) { looper = Looper.myLooper(); if (looper != null) { looper.quit(); } } }
From source file:com.jaspersoft.android.jaspermobile.cookie.LollipopCookieManager.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/* w w w . j av a2s.com*/ protected void semanticConfiguration(final String targetDomain) { final CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeSessionCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { cookieManager.setCookie(targetDomain, StringUtils.join(getCookieStore(), ";")); CookieManager.getInstance().flush(); } }); }
From source file:org.schabi.newpipe.ReCaptchaActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recaptcha); // Set return to Cancel by default setResult(RESULT_CANCELED);//from w ww.j av a 2 s . com Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(R.string.reCaptcha_title); actionBar.setDisplayShowTitleEnabled(true); } WebView myWebView = (WebView) findViewById(R.id.reCaptchaWebView); // Enable Javascript WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); ReCaptchaWebViewClient webClient = new ReCaptchaWebViewClient(this); myWebView.setWebViewClient(webClient); // Cleaning cache, history and cookies from webView myWebView.clearCache(true); myWebView.clearHistory(); android.webkit.CookieManager cookieManager = CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.removeAllCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean aBoolean) { } }); } else { cookieManager.removeAllCookie(); } myWebView.loadUrl(YT_URL); }
From source file:com.mario22gmail.license.nfc_project.FragmentBrowser.java
@Override public void onPause() { Log.i("nfc_debug", "browser on pause"); android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.removeAllCookies(new ValueCallback<Boolean>() { // a callback which is executed when the cookies have been removed @Override/*from w w w.j av a2 s .co m*/ public void onReceiveValue(Boolean aBoolean) { Log.d("nfc_debug", "Cookie removed: " + aBoolean); } }); } else cookieManager.removeAllCookie(); mWebview.clearCache(true); mWebview.removeAllViews(); mWebview.clearHistory(); mWebview.clearFormData(); super.onPause(); }
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 ww w . j ava2 s . co 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 } }); }
From source file:com.mario22gmail.license.nfc_project.FragmentBrowser.java
@Override public void onStop() { Log.i("nfc_debug", "browser on stop"); android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.removeAllCookies(new ValueCallback<Boolean>() { // a callback which is executed when the cookies have been removed @Override/*from w w w . j av a 2 s .c o m*/ public void onReceiveValue(Boolean aBoolean) { Log.d("nfc_debug", "Cookie removed: " + aBoolean); } }); } else cookieManager.removeAllCookie(); mWebview.clearCache(true); mWebview.clearFormData(); mWebview.removeAllViews(); mWebview.clearHistory(); mWebview.loadUrl("www.google.com"); super.onStop(); }
From source file:com.mario22gmail.license.nfc_project.FragmentBrowser.java
@Override public void onDestroy() { Log.i("nfc_debug", "browser on stop"); android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.removeAllCookies(new ValueCallback<Boolean>() { // a callback which is executed when the cookies have been removed @Override//from www . jav a 2s .c o m public void onReceiveValue(Boolean aBoolean) { Log.d("nfc_debug", "Cookie removed: " + aBoolean); } }); } else cookieManager.removeAllCookie(); mWebview.clearCache(true); mWebview.removeAllViews(); mWebview.clearFormData(); mWebview.clearHistory(); super.onDestroy(); }
From source file:org.microg.gms.auth.login.LoginActivity.java
private void init() { setTitle(R.string.just_a_sec);//from w ww.j a va2 s .c o m setBackButtonText(null); setNextButtonText(null); View loading = getLayoutInflater().inflate(R.layout.login_assistant_loading, authContent, false); authContent.removeAllViews(); authContent.addView(loading); setMessage(R.string.auth_connecting); CookieManager.getInstance().setAcceptCookie(true); if (SDK_INT >= LOLLIPOP) { CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { start(); } }); } else { //noinspection deprecation CookieManager.getInstance().removeAllCookie(); start(); } }
From source file:com.mario22gmail.license.nfc_project.FragmentBrowser.java
public void OpenWebSite(String urlFromCredential, String javaScript) { mWebview.loadUrl(urlFromCredential); WebSettings settings = mWebview.getSettings(); settings.setJavaScriptEnabled(true); urlEditText.setText(urlFromCredential); final String javaScriptFinal = javaScript; final String urlFromCredentialFinal = urlFromCredential; mWebview.setWebViewClient(new WebViewClient() { @Override//from w ww. ja v a2 s .c om public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (url.startsWith(urlFromCredentialFinal)) { if (Build.VERSION.SDK_INT >= 19) { view.evaluateJavascript(javaScriptFinal, new ValueCallback<String>() { @Override public void onReceiveValue(String s) { } }); } else { view.loadUrl(javaScriptFinal); } } } }); }
From source file:com.intel.xdk.device.Device.java
@Override public void initialize(CordovaInterface cordova, final CordovaWebView webView) { super.initialize(cordova, webView); this.activity = cordova.getActivity(); this.webView = webView; //remote site support remoteLayout = new AbsoluteLayout(activity); remoteLayout.setBackgroundColor(Color.BLACK); //hide the remote site display until needed remoteLayout.setVisibility(View.GONE); //create the close button remoteClose = new ImageButton(activity); remoteClose.setBackgroundColor(Color.TRANSPARENT); Drawable remoteCloseImage = null;/* w w w . j a va 2 s. c o m*/ remoteCloseImage = activity.getResources().getDrawable( activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName())); File remoteCloseImageFile = new File(activity.getFilesDir(), "_intelxdk/remote_close.png"); if (remoteCloseImageFile.exists()) { remoteCloseImage = (Drawable.createFromPath(remoteCloseImageFile.getAbsolutePath())); } else { remoteCloseImage = (activity.getResources().getDrawable( activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName()))); } //set the button image //remoteClose.setImageDrawable(remoteCloseImage); remoteClose.setBackgroundDrawable(remoteCloseImage); //set up the button click action remoteClose.setOnClickListener(new OnClickListener() { public void onClick(View v) { closeRemoteSite(); } }); //add the close button remoteLayout.addView(remoteClose); final ViewGroup parent = (ViewGroup) webView.getEngine().getView().getParent(); activity.runOnUiThread(new Runnable() { public void run() { if (parent != null) { //add layout to activity root layout parent.addView(remoteLayout, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER)); } } }); //Initialize the orientation. lastOrientation = "unknown"; //Listen to the orientation change. OrientationEventListener listener = new OrientationEventListener(activity) { @Override public void onOrientationChanged(int orientation) { //Log.d("orientation","orientation: " + orientation); String currentOrientation = "unknown"; boolean orientationChanged = false; //int displayOrientation = 0; if (orientation > 345 || orientation < 15) { currentOrientation = "portrait"; displayOrientation = 0; } else if (orientation > 75 && orientation < 105) { currentOrientation = "landscape"; displayOrientation = 90; } else if (orientation > 165 && orientation < 195) { currentOrientation = "portrait"; displayOrientation = 180; } else if (orientation > 255 && orientation < 285) { currentOrientation = "landscape"; displayOrientation = -90; } if (currentOrientation.equals("unknown")) { currentOrientation = lastOrientation; } if (!currentOrientation.equals(lastOrientation)) { orientationChanged = true; Log.d("orientation", "Orientation changes from " + lastOrientation + " to " + currentOrientation + ", current orientation: " + orientation + "."); } if (orientationChanged) { String js = "javascript:try{intel.xdk.device.orientation='" + displayOrientation + "';}catch(e){}var e = document.createEvent('Events');e.initEvent('intel.xdk.device.orientation.change', true, true);e.success=true;e.orientation='" + displayOrientation + "';document.dispatchEvent(e);"; injectJS(js); } lastOrientation = currentOrientation; } }; listener.enable(); registerScreenStatusReceiver(); //cache references to methods for use in injectJS try { evaluateJavascript = webView.getClass().getMethod("evaluateJavascript", String.class, ValueCallback.class); } catch (Exception e) { } try { sendJavascript = webView.getClass().getMethod("sendJavascript", String.class); } catch (Exception e) { } emptyVC = new ValueCallback<String>() { @Override public void onReceiveValue(String s) { } }; }