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:net.evecom.android.web.WebdbActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    temp = HttpUtil.getPageSize(this);
    setContentView(R.layout.message_post_web);
    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();
    /**//w w  w  .  j a  v  a 2  s  .  c om
     * WebViewJavaScript
     */
    webView.getSettings().setJavaScriptEnabled(true);
    /**
     * loadUrl()
     */
    HelloWebViewClient client = new HelloWebViewClient();
    webView.setWebViewClient(client);
    dialog = ProgressDialog.show(WebdbActivity.this, null, "..");
    dialog.setCancelable(true);
    // http://harlan-pc/fzaj/emergency/mobileWebApp/publicInfo/login.do?userName=zf1&userPwd=1
    // webView.loadUrl("http://www.baidu.com");
    // String url = HttpUtil.BASE_PC_URL
    // String url =HttpUtil.BASE_PC_URL+"loginController/messageLogin";
    String url = HttpUtil.BASE_PC_URL + "mobile/loginController/eventlistLogin";
    // post
    // http://wangzy:8081/gssms/mobile/loginController/eventlistLogin?loginname=sysadmin&pwd=888888
    // String postDate = "loginname=sysadmin&pwd=888888";
    String postDate = "loginname=" + ShareUtil.getString(getApplicationContext(), "SESSION", "USERNAME", "")
            + "&pwd=" + ShareUtil.getString(getApplicationContext(), "SESSION", "PASSWORD", "") + "&pageSize="
            + temp;
    // webView.postUrl(url, postData) postDatabyte[] 
    // EncodingUtils.getBytes(data, charset)
    webView.postUrl(url, EncodingUtils.getBytes(postDate, "BASE64"));
    // 
    webView.setDownloadListener(new MyWebViewDownLoadListener());
    WebSettings webSettings = webView.getSettings();
    webSettings.setSupportZoom(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setBuiltInZoomControls(true);// support zoom
    // webSettings.setPluginsEnabled(true);//support flash
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    // webSettings.setPluginsEnabled(true); //(flash)

    /**  */
    // //
    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;
    // DebugLog.d(TAG, "densityDpi = " + mDensity);
    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);
    }
    webView.setWebChromeClient(m_chromeClient);// (flash)
    dialogPress = new AlertDialog.Builder(this).setTitle("").setMessage(":0/0")
            .setPositiveButton("", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
}

From source file:net.evecom.android.web.Web0Activity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    temp = HttpUtil.getPageSize(this);
    setContentView(R.layout.message_post_web);
    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();
    /**/*from w w  w.j a  va  2  s  . c o m*/
     * WebViewJavaScript
     */
    webView.getSettings().setJavaScriptEnabled(true);
    /**
     * loadUrl()
     */
    webView.setWebViewClient(new HelloWebViewClient());
    dialog = ProgressDialog.show(Web0Activity.this, null, "..");
    dialog.setCancelable(true);
    // http://harlan-pc/fzaj/emergency/mobileWebApp/publicInfo/login.do?userName=zf1&userPwd=1
    // webView.loadUrl("http://www.baidu.com");
    // String url = HttpUtil.BASE_PC_URL
    // String url =HttpUtil.BASE_PC_URL+"loginController/messageLogin";
    String url = HttpUtil.BASE_PC_URL + "mobile/loginController/messageLogin";
    // post
    String postDate = "loginname=" + ShareUtil.getString(getApplicationContext(), "SESSION", "USERNAME", "")
            + "&pwd=" + ShareUtil.getString(getApplicationContext(), "SESSION", "PASSWORD", "") + "&pageSize="
            + temp;
    // webView.postUrl(url, postData) postDatabyte[] 
    // EncodingUtils.getBytes(data, charset)
    webView.postUrl(url, EncodingUtils.getBytes(postDate, "BASE64"));
    // 
    webView.setDownloadListener(new MyWebViewDownLoadListener());
    WebSettings webSettings = webView.getSettings();
    webSettings.setSupportZoom(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setBuiltInZoomControls(true);// support zoom
    // webSettings.setPluginsEnabled(true);//support flash
    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);

    // webSettings.setPluginsEnabled(true); //(flash)
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int mDensity = metrics.densityDpi;
    // DebugLog.d(TAG, "densityDpi = " + mDensity);
    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);
    }
    webView.setWebChromeClient(m_chromeClient);// (flash)
    dialogPress = new AlertDialog.Builder(this).setTitle("").setMessage(":0/0")
            .setPositiveButton("", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
}

From source file:org.andrico.andjax.http.HttpMessageFactory.java

/**
 * Create a new http uri request and submit for execution. Promote this to
 * public when I need to actually instantiate an HttpMessage with these
 * parameters./*  ww  w. j  av  a2 s .  c o m*/
 * 
 * @param url The url that this request will access.
 * @param multipartEntity The MultipartEntity to send with the request.
 * @return
 * @throws URISyntaxException
 */
public HttpMessage createFromParts(String url, MultipartEntity multipartEntity) throws URISyntaxException {
    HttpMessage method;
    if (multipartEntity == null) {
        Log.d("HttpMessageFactory", "Using HttpGet");
        method = new HttpGet(url);
    } else {
        Log.d("HttpMessageFactory", "Using HttpPost");
        method = new HttpPost(url);
        ((HttpPost) method).setEntity(multipartEntity);
    }

    if (mCookieDomain != null) {
        final CookieManager cookieManager = CookieManager.getInstance();
        method.addHeader("Cookie", cookieManager.getCookie(this.mCookieDomain));
    }
    ;
    return method;
}

From source file:org.dmfs.oauth2.android.fragment.InteractiveGrantFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Nullable// ww w .j a v  a2 s  .co  m
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    if (mWebView == null) {
        // create and configure the WebView
        // Note using just getActivity would will leak the activity.
        mWebView = new WebView(getActivity().getApplicationContext());
        mWebView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.setOnKeyListener(this);
        mWebView.setWebViewClient(mGrantWebViewClient);
        mWebView.loadUrl(mGrant.authorizationUrl().toASCIIString());

        // wipe cookies to enforce a new login
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
        } else {
            CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(getActivity());
            cookieSyncMngr.startSync();
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.removeAllCookie();
            cookieManager.removeSessionCookie();
            cookieSyncMngr.stopSync();
            cookieSyncMngr.sync();
        }
    }
    return mWebView;
}

From source file:com.citrus.mobile.User.java

public final static boolean logoutUser(Activity activity) {

    CookieSyncManager.createInstance(activity);

    CookieManager.getInstance().setCookie(Config.getBaseURL(), Constants.CITRUS_PREPAID_COOKIE);//remove App Cookie

    new PersistentConfig(activity).clearToken(); //clear stored cookies

    OauthToken token = new OauthToken(activity, "");
    return token.clearToken(); //clear stored oauth token

}

From source file:com.javielinux.facebook.FacebookHandler.java

public void showWebView() {
    if (isWebViewShown) {
        return;/*  ww  w. j a  v a  2  s.c o  m*/
    }

    CookieSyncManager.createInstance(activity);

    mWebView = new WebView(activity);

    layout.addView(mWebView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    CookieManager.getInstance().removeAllCookie();
    CookieManager.getInstance().removeExpiredCookie();
    CookieManager.getInstance().removeSessionCookie();

    CookieSyncManager.getInstance().sync();

    isWebViewShown = true;
}

From source file:com.amgems.uwschedule.api.uw.LoginAuthenticator.java

private LoginAuthenticator(Context context, Handler handler, HttpClient httpClient, String username,
        String password) {//from  w w w . ja  va 2 s.c om
    mUsername = username;
    mPassword = password;
    mCookiesValue = "";

    mHttpClient = httpClient;
    mLoadingFinished = false;
    mJsWebview = new WebView(context);
    mHandler = handler;
    CookieManager.getInstance().removeAllCookie();
    mJsWebview.getSettings().setJavaScriptEnabled(true);
    mJsWebview.addJavascriptInterface(new CaptureHtmBody(), CaptureHtmBody.INTERFACE_NAME);
    mJsWebview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            // If the page has been loaded before, then the WebView must have
            // returned from a JavaScript redirect required for
            // appropriate login cookies. This is when the html content
            // should be captured and processed
            if (mPageLoadCount >= 1)
                view.loadUrl(CaptureHtmBody.CAPTURE_HTML_SCRIPT);
            mPageLoadCount++;
        }
    });
}

From source file:stack.com.stackapi.ui.StackBaseActivity.java

public void clearCookies() {
    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
}

From source file:com.offbye.bookmaster.android.book.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  w  w. j  a va  2  s  . c o  m
    if (intent == null || (!intent.getAction().equals(Intents.SearchBookContents.ACTION))) {
        finish();
        return;
    }

    isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN);
    if (isbn.startsWith("http://google.com/books?id=")) {
        setTitle(getString(R.string.sbc_name));
    } else {
        setTitle(getString(R.string.sbc_name) + ": ISBN " + isbn);
    }

    setContentView(R.layout.search_book_contents);
    queryTextView = (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
        queryTextView.setText(initialQuery);
    }
    queryTextView.setOnKeyListener(keyListener);

    queryButton = (Button) findViewById(R.id.query_button);
    queryButton.setOnClickListener(buttonListener);

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

From source file:org.kotemaru.android.sample.webview.XMLHttpRequestXS.java

@JavascriptInterface
public String open(String type, String url, boolean isAsync) throws Exception {
    Log.d(TAG, "open:" + type + " " + url);
    try {//from w w  w.  jav  a2s  .  c o  m
        _isAsync = isAsync;
        if (GET.equalsIgnoreCase(type)) {
            _request = new HttpGet(url);
        } else {
            _request = new HttpPost(url);
        }
        _factory.checkDomain(_request.getURI());

        String cookie = CookieManager.getInstance().getCookie(url);
        _request.setHeader("Cookie", cookie);
        setReadyState(OPENED);
        return null;
    } catch (Throwable t) {
        Log.e(TAG, t.getMessage(), t);
        setReadyState(ERROR);
        return t.getMessage();
    }
}