Example usage for android.webkit CookieSyncManager getInstance

List of usage examples for android.webkit CookieSyncManager getInstance

Introduction

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

Prototype

public static CookieSyncManager getInstance() 

Source Link

Document

Singleton access to a CookieSyncManager .

Usage

From source file:Main.java

public static void setCookie(Context context, String url) {
    FileInputStream in = null;/*from w w  w  . ja v  a 2 s .c om*/
    try {
        in = context.openFileInput(TAXICOOKIE_FILE);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    if (in == null) {
        Log.w(TAG, "saveCookie: Cannot open file: " + TAXICOOKIE_FILE);
    }

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String cookieStr = null;
    try {
        cookieStr = reader.readLine();
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(TAG, "cookieStr: " + cookieStr);
    if (cookieStr == null) {
        return;
    }

    CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeSessionCookie();
    cookieManager.setCookie(url, cookieStr);
    CookieSyncManager.getInstance().sync();
}

From source file:com.jaspersoft.android.jaspermobile.cookie.LegacyCookieManager.java

@Override
public void semanticConfiguration(String targetDomain) {
    CookieSyncManager.createInstance(getContext());

    final CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeSessionCookie();
    cookieManager.setCookie(targetDomain, StringUtils.join(getCookieStore(), ";"));
    CookieSyncManager.getInstance().sync();
}

From source file:com.swiftkaydevelopment.fullsailcommunicate.fragments.AssignmentViewFragment.java

@Nullable
@Override//from  www. j a v a2 s  .c om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mWebView = new WebView(getActivity());
    CookieSyncManager.createInstance(getActivity());
    CookieSyncManager.getInstance().startSync();
    mWebView.getSettings().supportZoom();
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl("https://course.fso.fullsail.edu/class_sections/66645/assignments/1047897");

    return mWebView;
}

From source file:biz.varkon.shelvesom.util.CookieStore.java

public String getCookie(String url) {
    final CookieManager cookieManager = CookieManager.getInstance();
    String cookie = cookieManager.getCookie(url);

    if (cookie == null || cookie.length() == 0) {
        final HttpHead head = new HttpHead(url);
        HttpEntity entity = null;/* w  ww .  j  av a2s.co m*/
        try {
            final HttpResponse response = HttpManager.execute(head);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                entity = response.getEntity();

                final Header[] cookies = response.getHeaders("set-cookie");
                for (Header cooky : cookies) {
                    cookieManager.setCookie(url, cooky.getValue());
                }

                CookieSyncManager.getInstance().sync();
                cookie = cookieManager.getCookie(url);
            }
        } catch (IOException e) {
            Log.e(LOG_TAG, "Could not retrieve cookie", e);
        } finally {
            if (entity != null) {
                try {
                    entity.consumeContent();
                } catch (IOException e) {
                    Log.e(LOG_TAG, "Could not retrieve cookie", e);
                }
            }
        }
    }

    return cookie;
}

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 . ja  v  a  2 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:com.android.browser.GoogleAccountLogin.java

private GoogleAccountLogin(Activity activity, Account account, Runnable runnable) {
    mActivity = activity;//from ww w.jav a 2  s  .co m
    mAccount = account;
    mWebView = new WebView(mActivity);
    mRunnable = runnable;
    mUserAgent = mWebView.getSettings().getUserAgentString();

    // XXX: Doing pre-login causes onResume to skip calling
    // resumeWebViewTimers. So to avoid problems with timers not running, we
    // duplicate the work here using the off-screen WebView.
    CookieSyncManager.getInstance().startSync();
    WebViewTimersControl.getInstance().onBrowserActivityResume(mWebView);

    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            done();
        }
    });
}

From source file:com.geozen.demo.foursquare.jiramot.Foursquare.java

private void startDialogAuth(Context activity) {
    CookieSyncManager.createInstance(activity);
    Bundle params = new Bundle();
    dialog(activity, LOGIN, params, new DialogListener() {

        public void onComplete(Bundle values) {
            // ensure any cookies set by the dialog are saved
            CookieSyncManager.getInstance().sync();
            String _token = values.getString(TOKEN);
            setAccessToken(_token);//from w  w w.  j a va2s  . c  om
            if (isSessionValid()) {
                Log.d("Foursquare-authorize", "Login Success! access_token=" + getAccessToken());
                mAuthDialogListener.onComplete(values);
            } else {
                mAuthDialogListener.onFoursquareError(new FoursquareError("Failed to receive access token."));
            }
        }

        public void onError(DialogError error) {
            Log.d("Foursquare-authorize", "Login failed: " + error);
            mAuthDialogListener.onError(error);
        }

        public void onFoursquareError(FoursquareError error) {
            Log.d("Foursquare-authorize", "Login failed: " + error);
            mAuthDialogListener.onFoursquareError(error);
        }

        public void onCancel() {
            Log.d("Foursquare-authorize", "Login canceled");
            mAuthDialogListener.onCancel();
        }
    });
}

From source file:net.evecom.androidecssp.base.BaseWebActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    temp = HttpUtil.getPageSize(this);
    setContentView(R.layout.message_post_web);
    // dialog = ProgressDialog.show(BaseWebActivity.this, null,
    // "..");/*from w  w w .  j  av  a 2 s  .c  om*/
    // dialog.setCancelable(true);

    lineProgressBar = (ProgressBar) findViewById(R.id.webview_progress_id);
    imageView = (ImageView) findViewById(R.id.image_view_at_web);
    webView = (WebView) this.findViewById(R.id.wv_oauth_message);
    CookieSyncManager.createInstance(this);
    CookieSyncManager.getInstance().startSync();
    CookieManager.getInstance().removeSessionCookie();

    webView.setWebViewClient(new BaseWebViewClient((BaseWebActivity) instance));
    webView.setWebChromeClient(new BaseChromeClient((BaseWebActivity) instance));

    // 
    webView.setDownloadListener(new MyWebViewDownLoadListener());
    WebSettings webSettings = webView.getSettings();
    webSettings.setSupportZoom(true);
    // WebViewJavaScript
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setBuiltInZoomControls(true);// support zoom
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    /**  */
    // //
    webSettings.setDatabaseEnabled(true);
    String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    // 
    webSettings.setGeolocationEnabled(true);
    // 
    webSettings.setGeolocationDatabasePath(dir);
    // 
    webSettings.setDomStorageEnabled(true);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int mDensity = metrics.densityDpi;
    if (mDensity == 240) {
        webSettings.setDefaultZoom(ZoomDensity.FAR);
    } else if (mDensity == 160) {
        webSettings.setDefaultZoom(ZoomDensity.MEDIUM);
    } else if (mDensity == 120) {
        webSettings.setDefaultZoom(ZoomDensity.CLOSE);
        // }else if(mDensity == DisplayMetrics..DENSITY_XHIGH){
        // webSettings.setDefaultZoom(ZoomDensity.FAR);
    } else if (mDensity == DisplayMetrics.DENSITY_HIGH) {
        webSettings.setDefaultZoom(ZoomDensity.FAR);
    }

    dialogPress = new AlertDialog.Builder(this).setTitle("").setMessage(":0/0")
            .setPositiveButton("", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();

    webView.addJavascriptInterface(new JsInterface(getApplicationContext()), "androidbase");
    String url = HttpUtil.getPCURL() + "jfs/mobile/androidIndex/jqmobileTest";
    // post
    // webView.postUrl(url, postData) postDatabyte[] 
    // EncodingUtils.getBytes("&pwd=888", charset)
    webView.postUrl(url, EncodingUtils.getBytes("", "BASE64"));

}

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();//from   w w  w.  j a v  a 2 s .  com
        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.hua.nowid.activity.WebViewFragment.java

public void updateSecureCookie() {
    CookieSyncManager.createInstance(this.getActivity().getApplicationContext());
    CookieManager cookieManager = CookieManager.getInstance();
    String cookieString = "NOWSESSIONID=" + NowIDLoginStatus.getInstance().getSecureCookie();
    cookieManager.removeAllCookie();/*  w w  w.  j av a  2  s  .com*/
    cookieManager.setCookie(".now.com", cookieString);
    Log.v("WebViewFragment", cookieString);
    CookieSyncManager.getInstance().sync();
}