Example usage for android.webkit CookieManager getInstance

List of usage examples for android.webkit CookieManager getInstance

Introduction

In this page you can find the example usage for android.webkit CookieManager getInstance.

Prototype

public static CookieManager getInstance() 

Source Link

Document

Gets the singleton CookieManager instance.

Usage

From source file:com.bez4pieci.cookies.Cookies.java

public void clear() {
    Log.v(TAG, "Clearing cookies...");
    CookieManager.getInstance().removeAllCookie();
}

From source file:com.zbrown.droidsteal.activities.HijackActivity.java

private void setupCookies() {
    Log.i(APPLICATION_TAG, "######################## COOKIE SETUP ###############################");
    CookieManager manager = CookieManager.getInstance();
    Log.i(APPLICATION_TAG, "Cookiemanager has cookies: " + (manager.hasCookies() ? "YES" : "NO"));
    if (manager.hasCookies()) {
        manager.removeAllCookie();/*from  w w w.j a  va2  s .  c o m*/
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            Log.e(APPLICATION_TAG, "Error with Thread.sleep(3000)", e);
        }
        Log.i(APPLICATION_TAG, "Cookiemanager has still cookies: " + (manager.hasCookies() ? "YES" : "NO"));
    }
    Log.i(APPLICATION_TAG, "######################## COOKIE SETUP START ###############################");
    for (CookieWrapper cookieWrapper : authToHijack.getCookies()) {
        Cookie cookie = cookieWrapper.getCookie();
        String cookieString = cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain()
                + "; Path=" + cookie.getPath();
        Log.i(APPLICATION_TAG, "Setting up cookie: " + cookieString);
        manager.setCookie(cookie.getDomain(), cookieString);
    }
    CookieSyncManager.getInstance().sync();
    Log.i(APPLICATION_TAG, "######################## COOKIE SETUP DONE ###############################");
}

From source file:cz.yetanotherview.developerconsole.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.tryAgainButton).setOnClickListener(this);

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    swipeRefreshLayout.setColorSchemeResources(R.color.primary, R.color.button);
    swipeRefreshLayout.setOnRefreshListener(this);

    browser = (WebView) findViewById(R.id.webView);
    browser.setWebViewClient(new MyBrowser());
    CookieManager.getInstance().setAcceptCookie(true);

    open();/* w ww .  jav  a2s.c om*/
}

From source file:de.baumann.browser.helper.helper_webView.java

@SuppressLint("SetJavaScriptEnabled")
public static void webView_Settings(final Activity from, final WebView webView) {

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
    String fontSizeST = sharedPref.getString("font", "100");
    int fontSize = Integer.parseInt(fontSizeST);

    webView.getSettings().setAppCachePath(from.getApplicationContext().getCacheDir().getAbsolutePath());
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setMixedContentMode(MIXED_CONTENT_COMPATIBILITY_MODE);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAllowContentAccess(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setTextZoom(fontSize);
    webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);

    from.registerForContextMenu(webView);

    if (sharedPref.getString("nav", "2").equals("1") || sharedPref.getString("nav", "2").equals("3")) {
        helper_webView.webView_Touch(from, webView);
    }/*from  w w w .ja  v  a2s . co m*/

    if (sharedPref.getString("cookie", "1").equals("2") || sharedPref.getString("cookie", "1").equals("3")) {
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView, true);
    } else {
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView, false);
    }

    if (sharedPref.getString("started", "").equals("yes")) {
        if (sharedPref.getString("java_string", "True").equals(from.getString(R.string.app_yes))) {
            webView.getSettings().setJavaScriptEnabled(true);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setJavaScriptEnabled(false);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("pictures_string", "True").equals(from.getString(R.string.app_yes))) {
            webView.getSettings().setLoadsImagesAutomatically(true);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setLoadsImagesAutomatically(false);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("loc_string", "True").equals(from.getString(R.string.app_yes))) {
            webView.getSettings().setGeolocationEnabled(true);
            helper_main.grantPermissionsLoc(from);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setGeolocationEnabled(false);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("cookie_string", "True").equals(from.getString(R.string.app_yes))) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply();
        } else {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(false);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply();
        }
    } else {
        if (sharedPref.getBoolean("java", false)) {
            webView.getSettings().setJavaScriptEnabled(true);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setJavaScriptEnabled(false);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getBoolean("pictures", false)) {
            webView.getSettings().setLoadsImagesAutomatically(true);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setLoadsImagesAutomatically(false);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getBoolean("loc", false)) {
            webView.getSettings().setGeolocationEnabled(true);
            helper_main.grantPermissionsLoc(from);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setGeolocationEnabled(false);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("cookie", "1").equals("1")
                || sharedPref.getString("cookie", "1").equals("3")) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply();
        } else {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(false);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply();
        }
    }
}

From source file:com.google.zxing.client.android.SearchBookContentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Make sure that expired cookies are removed on launch.
    CookieSyncManager.createInstance(this);
    CookieManager.getInstance().removeExpiredCookie();

    Intent intent = getIntent();/*from ww w  . ja  v  a2 s  .  c  o  m*/
    if (intent == null || (!intent.getAction().equals(Intents.SearchBookContents.ACTION)
            && !intent.getAction().equals(Intents.SearchBookContents.DEPRECATED_ACTION))) {
        finish();
        return;
    }

    mISBN = intent.getStringExtra(Intents.SearchBookContents.ISBN);
    setTitle(getString(R.string.sbc_name) + ": ISBN " + mISBN);

    setContentView(R.layout.search_book_contents);
    mQueryTextView = (EditText) findViewById(R.id.query_text_view);

    String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY);
    if (initialQuery != null && initialQuery.length() > 0) {
        // Populate the search box but don't trigger the search
        mQueryTextView.setText(initialQuery);
    }
    mQueryTextView.setOnKeyListener(mKeyListener);

    mQueryButton = (Button) findViewById(R.id.query_button);
    mQueryButton.setOnClickListener(mButtonListener);

    mResultListView = (ListView) findViewById(R.id.result_list_view);
    LayoutInflater factory = LayoutInflater.from(this);
    mHeaderView = (TextView) factory.inflate(R.layout.search_book_contents_header, mResultListView, false);
    mResultListView.addHeaderView(mHeaderView);

    mUserAgent = getString(R.string.zxing_user_agent);
}

From source file:thiru.in.basicauthwebview.ShowWebViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_show_web_view);

    // Initialize the Cookie Manager
    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);

    String url = "http://auth.thiru.in/";
    // Call the REST Service to Authenticate
    // This is sample app, the app can have a login form, accept input, encode the
    // id and passowrd using Base64 for Validating
    AsyncTask<String, Void, CookieStore> cookieStoreTask = new Authenticate(this).execute(url + "app-auth",
            "ZGVtbzpkZW1v"); //Base64 Encoded for demo:demo

    try {//from ww  w  .  j  ava  2s .c o  m
        cookieManager.removeAllCookie();
        CookieStore cookieStore = cookieStoreTask.get();
        List<Cookie> cookies = cookieStore.getCookies();
        // If the User id and password is wrong, the cookie store will not have any cookies
        // And the page will display 403 Access Denied
        for (Cookie cookie : cookies) {
            Log.i("Cookie", cookie.getName() + " ==> " + cookie.getValue());
            // Add the REST Service Cookie Responses to Cookie Manager to make it
            // Available for the WebViewClient
            cookieManager.setCookie(url, cookie.getName() + "=" + cookie.getValue());
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

    mWebView = (WebView) findViewById(R.id.activity_main_webview);
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.loadUrl(url);
}

From source file:de.trier.infsec.koch.droidsheep.activities.HijackActivity.java

private void setupCookies() {
    Log.i(APPLICATION_TAG, "######################## COOKIE SETUP ###############################");
    CookieManager manager = CookieManager.getInstance();
    Log.i(APPLICATION_TAG, "Cookiemanager has cookies: " + (manager.hasCookies() ? "YES" : "NO"));
    if (manager.hasCookies()) {
        manager.removeAllCookie();/*  w w  w . ja va 2  s.  c o m*/
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
        }
        Log.i(APPLICATION_TAG, "Cookiemanager has still cookies: " + (manager.hasCookies() ? "YES" : "NO"));
    }
    Log.i(APPLICATION_TAG, "######################## COOKIE SETUP START ###############################");
    for (CookieWrapper cookieWrapper : authToHijack.getCookies()) {
        Cookie cookie = cookieWrapper.getCookie();
        String cookieString = cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain()
                + "; Path=" + cookie.getPath();
        Log.i(APPLICATION_TAG, "Setting up cookie: " + cookieString);
        manager.setCookie(cookie.getDomain(), cookieString);
    }
    CookieSyncManager.getInstance().sync();
    Log.i(APPLICATION_TAG, "######################## COOKIE SETUP DONE ###############################");
}

From source file:com.androidrocks.bex.zxing.client.android.SearchBookContentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Make sure that expired cookies are removed on launch.
    CookieSyncManager.createInstance(this);
    CookieManager.getInstance().removeExpiredCookie();

    Intent intent = getIntent();//from  w ww.  j  av a 2  s  .c o  m
    if (intent == null || (!intent.getAction().equals(Intents.SearchBookContents.ACTION)
            && !intent.getAction().equals(Intents.SearchBookContents.DEPRECATED_ACTION))) {
        finish();
        return;
    }

    mISBN = intent.getStringExtra(Intents.SearchBookContents.ISBN);
    setTitle(getString(R.string.sbc_name) + ": ISBN " + mISBN);

    setContentView(R.layout.search_book_contents);
    mQueryTextView = (EditText) findViewById(R.id.query_text_view);

    String initialQuery = intent.getStringExtra(Intents.SearchBookContents.QUERY);
    if (initialQuery != null && initialQuery.length() > 0) {
        // Populate the search box but don't trigger the search
        mQueryTextView.setText(initialQuery);
    }
    mQueryTextView.setOnKeyListener(mKeyListener);

    mQueryButton = (Button) findViewById(R.id.query_button);
    mQueryButton.setOnClickListener(mButtonListener);

    mResultListView = (ListView) findViewById(R.id.result_list_view);
    LayoutInflater factory = LayoutInflater.from(this);
    mHeaderView = (TextView) factory.inflate(R.layout.search_book_contents_header, mResultListView, false);
    mResultListView.addHeaderView(mHeaderView);
}

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   ww w. j  av  a2 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:org.zywx.wbpalmstar.widgetone.WidgetOneApplication.java

@Override
public void onCreate() {
    super.onCreate();
    EUExUtil.init(this);
    CookieSyncManager.createInstance(this);
    CookieManager.getInstance().setAcceptCookie(true);
    CookieManager.getInstance().removeSessionCookie();
    CookieManager.getInstance().removeExpiredCookie();
    mCrashReport = new ECrashHandler();
    cachePath = getCacheDir().getAbsolutePath();
    copyLib();/*from   www  . ja va2s.c o m*/
    copyJar();
    initClassLoader();

}