类android.webkit.CookieManager源码实例Demo

下面列出了怎么用android.webkit.CookieManager的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xGetter   文件: GDrive2020.java
private static void out(String result){
    destroyWebView();
    if (result!=null){
        ArrayList<XModel> xModels = new ArrayList<>();
        try {
            JSONArray jsonArray = new JSONArray(result);
            for(int i=0;i<jsonArray.length();i++){
                String url = jsonArray.getJSONObject(i).getString("file"),quality = jsonArray.getJSONObject(i).getString("label"),cookies = CookieManager.getInstance().getCookie(url);
                XModel model = new XModel();
                model.setUrl(url);
                model.setQuality(quality);
                model.setCookie(cookies);
                xModels.add(model);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        onTaskCompleted.onTaskCompleted(Utils.sortMe(xModels),true);
    }else onTaskCompleted.onError();
}
 
源代码2 项目: Lucid-Browser   文件: MainActivity.java
/**
	 * Clears browser cache etc
	 */
    protected void clearTraces(){
    	CustomWebView WV = webLayout.findViewById(R.id.browser_page);
    	if (WV!=null){
			WV.clearHistory();
			WV.clearCache(true);
    	}
		
		WebViewDatabase wDB = WebViewDatabase.getInstance(activity);
		wDB.clearFormData();
		
		CookieSyncManager.createInstance(activity);
		CookieManager cookieManager = CookieManager.getInstance();
		cookieManager.removeAllCookie();
		// Usefull for future commits:
//			cookieManager.setAcceptCookie(false)
//
//			WebView webview = new WebView(this);
//			WebSettings ws = webview.getSettings();
//			ws.setSaveFormData(false);
//			ws.setSavePassword(false); // Not needed for API level 18 or greater (deprecat
    }
 
private DownloadListener getDownloadListener() {
    return new DownloadListener() {
        public void onDownloadStart(
            String url,
            String userAgent,
            String contentDisposition,
            String mimetype,
            long contentLength
        ) {
            Uri uri = Uri.parse(url);
            Request request = new Request(uri);
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setTitle("File download from Mattermost");

            String cookie = CookieManager.getInstance().getCookie(url);
            if (cookie != null) {
                request.addRequestHeader("cookie", cookie);
            }

            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            dm.enqueue(request);
       }
    };
}
 
源代码4 项目: facebooklogin   文件: FacebookLoginActivity.java
private static void clearCookiesForDomain(Context context, String domain) {
    // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager
    // has never been created.
    CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
    syncManager.sync();

    CookieManager cookieManager = CookieManager.getInstance();

    String cookies = cookieManager.getCookie(domain);
    if (cookies == null) {
        return;
    }

    String[] splitCookies = cookies.split(";");
    for (String cookie : splitCookies) {
        String[] cookieParts = cookie.split("=");
        if (cookieParts.length > 0) {
            String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;";
            cookieManager.setCookie(domain, newCookie);
        }
    }
    cookieManager.removeExpiredCookie();
}
 
源代码5 项目: kakao-android-sdk-standalone   文件: Session.java
/**
 * 세션을 close하여 처음부터 새롭게 세션 open을 진행한다.
 * @param kakaoException  exception이 발생하여 close하는 경우 해당 exception을 넘긴다.
 * @param forced 강제 close 여부. 강제 close이면 이미 close가 되었어도 callback을 호출한다.
 */
private void internalClose(final KakaoException kakaoException, final boolean forced) {
    synchronized (INSTANCE_LOCK) {
        final SessionState previous = state;
        state = SessionState.CLOSED;
        requestType = null;
        authorizationCode = AuthorizationCode.createEmptyCode();
        accessToken = AccessToken.createEmptyToken();
        onStateChange(previous, state, requestType, kakaoException, forced);
    }
    if (this.appCache != null) {
        this.appCache.clearAll();
    }
    // 해당 도메인 cookie만 지우려고 했으나 CookieManager가 관리하는 cookie가 한 app에 대한 cookie여서 모두 날려도 되겠다.
    // CookieManager를 쓰려면 CookieSyncManager를 만들어야 하는 버그가 있다.
    CookieSyncManager.createInstance(context.getApplicationContext());
    CookieManager.getInstance().removeAllCookie();
}
 
源代码6 项目: pre-dem-android   文件: WebViewActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //清除cookie
    CookieSyncManager.createInstance(WebViewActivity.this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    setContentView(R.layout.activity_webview);

    mWebView = (WebView) findViewById(R.id.login_webview);

    mIntent = getIntent();
    mUrl = mIntent.getStringExtra("extr_url");

    mProgress = (ProgressBar) findViewById(R.id.login_webview_progress);

    init();
}
 
源代码7 项目: kognitivo   文件: Utility.java
private static void clearCookiesForDomain(Context context, String domain) {
    // This is to work around a bug where CookieManager may fail to instantiate if
    // CookieSyncManager has never been created.
    CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
    syncManager.sync();

    CookieManager cookieManager = CookieManager.getInstance();

    String cookies = cookieManager.getCookie(domain);
    if (cookies == null) {
        return;
    }

    String[] splitCookies = cookies.split(";");
    for (String cookie : splitCookies) {
        String[] cookieParts = cookie.split("=");
        if (cookieParts.length > 0) {
            String newCookie = cookieParts[0].trim() +
                    "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;";
            cookieManager.setCookie(domain, newCookie);
        }
    }
    cookieManager.removeExpiredCookie();
}
 
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);

    // CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager.getInstance().sync();
    }

    // https://issues.apache.org/jira/browse/CB-11248
    view.clearFocus();
    view.requestFocus();

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);

        sendUpdate(obj, true);
    } catch (JSONException ex) {
        LOG.d(LOG_TAG, "Should never happen");
    }
}
 
源代码9 项目: platform-friends-android   文件: Utility.java
private static void clearCookiesForDomain(Context context, String domain) {
    // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager
    // has never been created.
    CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
    syncManager.sync();

    CookieManager cookieManager = CookieManager.getInstance();

    String cookies = cookieManager.getCookie(domain);
    if (cookies == null) {
        return;
    }

    String[] splitCookies = cookies.split(";");
    for (String cookie : splitCookies) {
        String[] cookieParts = cookie.split("=");
        if (cookieParts.length > 0) {
            String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;";
            cookieManager.setCookie(domain, newCookie);
        }
    }
    cookieManager.removeExpiredCookie();
}
 
源代码10 项目: appcan-android   文件: ACEWebView.java
public void init(EBrowserView eBrowserView) {
    mBroView = eBrowserView;
    mWebApp=true;
    if (Build.VERSION.SDK_INT <= 7) {
        if (mBaSetting == null) {
            mBaSetting = new EBrowserSetting(eBrowserView);
            mBaSetting.initBaseSetting(mWebApp);
            setWebViewClient(mEXWebViewClient = new CBrowserWindow());
            setWebChromeClient(new CBrowserMainFrame(eBrowserView.getContext()));
        }

    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            // 适配Android5.0无法正常保存和携带cookie的问题
            CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
        }
        if (mBaSetting == null) {
            mBaSetting = new EBrowserSetting7(eBrowserView);
            mBaSetting.initBaseSetting(mWebApp);
            setWebViewClient(mEXWebViewClient = new CBrowserWindow7());
            setWebChromeClient(new CBrowserMainFrame7(eBrowserView.getContext()));
        }

    }
}
 
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mSpinner = new ProgressDialog(getContext());
  mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
  mSpinner.setMessage("Loading...");
  mContent = new LinearLayout(getContext());
  mContent.setOrientation(LinearLayout.VERTICAL);
  setUpTitle();
  setUpWebView();
  Display display = getWindow().getWindowManager().getDefaultDisplay();
  final float scale = getContext().getResources().getDisplayMetrics().density;
  float[] dimensions =
      (display.getWidth() < display.getHeight()) ? DIMENSIONS_PORTRAIT : DIMENSIONS_LANDSCAPE;
  addContentView(mContent, new FrameLayout.LayoutParams((int) (dimensions[0] * scale + 0.5f),
      (int) (dimensions[1] * scale + 0.5f)));
  CookieSyncManager.createInstance(getContext());
  CookieManager cookieManager = CookieManager.getInstance();
  cookieManager.removeAllCookie();
}
 
源代码12 项目: Huochexing12306   文件: WebViewUtil.java
private static void saveCookie(String url){
	String cookie = CookieManager.getInstance().getCookie(url);
	if(cookie !=null && !cookie.equals("")){  
           String[] cookies = cookie.split(";");  
           for(int i=0; i< cookies.length; i++){  
               String[] nvp = cookies[i].split("=");  
               BasicClientCookie c = new BasicClientCookie(nvp[0], nvp[1]);  
               //c.setVersion(0);  
               c.setDomain("kyfw.12306.cn");
               MyCookieStore myCookieStore = null;
               if (MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore()
               		instanceof MyCookieStore){
               	myCookieStore = (MyCookieStore)MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore();
               }
               if (myCookieStore != null){
               	myCookieStore.addCookie(c);
               }
           }
      }  
	CookieSyncManager.getInstance().sync();
}
 
源代码13 项目: AgentWeb   文件: AgentWebConfig.java
public static void removeSessionCookies(ValueCallback<Boolean> callback) {
    if (callback == null) {
        callback = getDefaultIgnoreCallback();
    }
    if (CookieManager.getInstance() == null) {
        callback.onReceiveValue(new Boolean(false));
        return;
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().removeSessionCookie();
        toSyncCookies();
        callback.onReceiveValue(new Boolean(true));
        return;
    }
    CookieManager.getInstance().removeSessionCookies(callback);
    toSyncCookies();
}
 
源代码14 项目: barterli_android   文件: Utility.java
private static void clearCookiesForDomain(Context context, String domain) {
    // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager
    // has never been created.
    CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
    syncManager.sync();

    CookieManager cookieManager = CookieManager.getInstance();

    String cookies = cookieManager.getCookie(domain);
    if (cookies == null) {
        return;
    }

    String[] splitCookies = cookies.split(";");
    for (String cookie : splitCookies) {
        String[] cookieParts = cookie.split("=");
        if (cookieParts.length > 0) {
            String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;";
            cookieManager.setCookie(domain, newCookie);
        }
    }
    cookieManager.removeExpiredCookie();
}
 
源代码15 项目: webTube   文件: TorHelper.java
public void torEnable() {
    CookieHelper.acceptCookies(webView, false);
    CookieHelper.deleteCookies();
    //Make sure that all cookies are really deleted
    if (!CookieManager.getInstance().hasCookies()) {
        if (!OrbotHelper.isOrbotRunning(mApplicationContext))
            OrbotHelper.requestStartTor(mApplicationContext);
        try {
            WebkitProxy.setProxy(MainActivity.class.getName(), mApplicationContext, null, "localhost", PORT_TOR);
            SharedPreferences.Editor spEdit = sp.edit();
            spEdit.putBoolean(PREF_TOR_ENABLED, true);
            spEdit.apply();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    webView.reload();
}
 
private String getExistingCookie() {
    try {
        CookieSyncManager.createInstance(PrebidMobile.getApplicationContext());
        CookieManager cm = CookieManager.getInstance();
        if (cm != null) {
            String wvcookie = cm.getCookie(PrebidServerSettings.COOKIE_DOMAIN);
            if (!TextUtils.isEmpty(wvcookie)) {
                String[] existingCookies = wvcookie.split("; ");
                for (String cookie : existingCookies) {
                    if (cookie != null && cookie.contains(PrebidServerSettings.AN_UUID)) {
                        return cookie;
                    }
                }
            }
        }
    } catch (Exception e) {
    }
    return null;
}
 
源代码17 项目: android-auth   文件: WebViewUtils.java
static void clearCookiesForDomain(Context context, String domain) {
    // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager
    // has never been created.
    CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
    syncManager.sync();

    CookieManager cookieManager = CookieManager.getInstance();

    String cookies = cookieManager.getCookie(domain);
    if (cookies == null) {
        return;
    }

    String[] splitCookies = cookies.split(";");
    for (String cookie : splitCookies) {
        String[] cookieParts = cookie.split("=");
        if (cookieParts.length > 0) {
            String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;";
            cookieManager.setCookie(domain, newCookie);
        }
    }
    cookieManager.removeExpiredCookie();
}
 
源代码18 项目: letv   文件: HttpTask.java
protected void sendResponseMessage(HttpResponse response) {
    super.sendResponseMessage(response);
    Header[] headers = response.getHeaders("Set-Cookie");
    if (headers != null && headers.length > 0) {
        CookieSyncManager.createInstance(LemallPlatform.getInstance().getContext()).sync();
        CookieManager instance = CookieManager.getInstance();
        instance.setAcceptCookie(true);
        instance.removeSessionCookie();
        String mm = "";
        for (Header header : headers) {
            String[] split = header.toString().split("Set-Cookie:");
            EALogger.i("游客登录", "split[1]===>" + split[1]);
            instance.setCookie(Constants.GUESTLOGIN, split[1]);
            int index = split[1].indexOf(";");
            if (TextUtils.isEmpty(mm)) {
                mm = split[1].substring(index + 1);
                EALogger.i("正式登录", "mm===>" + mm);
            }
        }
        EALogger.i("游客登录", "split[11]===>COOKIE_DEVICE_ID=" + LemallPlatform.getInstance().uuid + ";" + mm);
        instance.setCookie(Constants.GUESTLOGIN, "COOKIE_DEVICE_ID=" + LemallPlatform.getInstance().uuid + ";" + mm);
        instance.setCookie(Constants.THIRDLOGIN, "COOKIE_APP_ID=" + LemallPlatform.getInstance().getmAppInfo().getId() + ";" + mm);
        CookieSyncManager.getInstance().sync();
        this.val$iLetvBrideg.reLoadWebUrl();
    }
}
 
源代码19 项目: JayPS-AndroidApp   文件: UploadActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.delete_cookies: {
            CookieSyncManager.createInstance(getActivity());
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.removeAllCookie();
            return true;
        }
        default: {
            return super.onOptionsItemSelected(item);
        }
    }
}
 
源代码20 项目: talk-android   文件: TalkClient.java
@Override
public Throwable handleError(RetrofitError cause) {
    if (cause.getResponse() == null) {
        return new NetworkConnectedException("no network connected, please check network connected");
    }
    int code = cause.getResponse().getStatus();
    if (code == 403) {
        ErrorResponseData errorBoyd = (ErrorResponseData) cause.getBodyAs(ErrorResponseData.class);
        if (errorBoyd != null) {
            if (errorBoyd.code == 201 || errorBoyd.code == 220) {
                RealmConfig.deleteRealm();
                MainApp.PREF_UTIL.clear();
                CookieManager cookieManager = CookieManager.getInstance();
                cookieManager.removeAllCookie();
                NotificationUtil.stopPush(MainApp.CONTEXT);
                Intent intent = new Intent(MainApp.CONTEXT, Oauth2Activity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                BizLogic.cancelSync();
                MainApp.CONTEXT.startActivity(intent);

                // disconnect message service
                Intent closeMsgIntent = new Intent(MainApp.CONTEXT, MessageService.class);
                closeMsgIntent.setAction(MessageService.ACTION_CLOSE);
                MainApp.CONTEXT.startService(closeMsgIntent);
            }
        }
    }
    return cause;
}
 
源代码21 项目: xGetter   文件: GPhotosUtils.java
private static void putModel(String url, String quality, ArrayList<XModel> model){
    for (XModel x:model){
        if (x.getQuality().equalsIgnoreCase(quality)){
            return;
        }
    }
    if (url!=null && quality!=null) {
        XModel xModel = new XModel();
        xModel.setUrl(url);
        xModel.setQuality(quality);
        xModel.setCookie(CookieManager.getInstance().getCookie(url));
        model.add(xModel);
    }
}
 
源代码22 项目: MiBandDecompiled   文件: SDK2APPReceiver.java
public void onReceive(Context context, Intent intent)
{
    CookieSyncManager.createInstance(context);
    String s = CookieManager.getInstance().getCookie("https://account.xiaomi.com");
    if (!TextUtils.isEmpty(s) && s.contains("userId=") && s.contains("passToken="))
    {
        String s1 = intent.getStringExtra("user_id");
        if (TextUtils.isEmpty(s1) || s1.equals(a(s)))
        {
            Intent intent1 = new Intent(APP2SDKReceiver.AUTH_ACTION_NAME);
            intent1.putExtra("pkg", context.getPackageName());
            context.sendBroadcast(intent1);
        }
    }
}
 
源代码23 项目: focus-android   文件: ClassicWebViewProvider.java
@Override
public void applyAppSettings(@NotNull Context context, @NotNull WebSettings webSettings, @NotNull SystemWebView systemWebView) {

    // Clear the cache so trackers previously loaded are removed
    systemWebView.clearCache(true);

    // We could consider calling setLoadsImagesAutomatically() here too (This will block images not loaded over the network too)
    webSettings.setBlockNetworkImage(Settings.getInstance(context).shouldBlockImages());
    webSettings.setJavaScriptEnabled(!Settings.getInstance(context).shouldBlockJavaScript());
    CookieManager.getInstance().setAcceptThirdPartyCookies(systemWebView, !Settings.getInstance
            (context).shouldBlockThirdPartyCookies());
    CookieManager.getInstance().setAcceptCookie(!Settings.getInstance(context)
            .shouldBlockCookies());
}
 
@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();
  if (intent == null || !intent.getAction().equals(Intents.SearchBookContents.ACTION)) {
    finish();
    return;
  }

  isbn = intent.getStringExtra(Intents.SearchBookContents.ISBN);
  if (LocaleManager.isBookSearchUrl(isbn)) {
    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.isEmpty()) {
    // Populate the search box but don't trigger the search
    queryTextView.setText(initialQuery);
  }
  queryTextView.setOnKeyListener(keyListener);

  queryButton = 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);
}
 
源代码25 项目: MHViewer   文件: MyTagsActivity.java
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
  CookieManager cookieManager = CookieManager.getInstance();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    cookieManager.flush();
    cookieManager.removeAllCookies(null);
    cookieManager.removeSessionCookies(null);
  } else {
    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this);
    cookieSyncManager.startSync();
    cookieManager.removeAllCookie();
    cookieManager.removeSessionCookie();
    cookieSyncManager.stopSync();
  }

  // Copy cookies from okhttp cookie store to CookieManager
  url = EhUrl.getMyTagsUrl();
  EhCookieStore store = EhApplication.getEhCookieStore(this);
  for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
    cookieManager.setCookie(url, cookie.toString());
  }

  setContentView(R.layout.activity_my_tags);
  setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
  webView = findViewById(R.id.webview);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new MyTagsWebViewClient());
  webView.setWebChromeClient(new DialogWebChromeClient(this));
  webView.loadUrl(url);
  progress = findViewById(R.id.progress);
}
 
源代码26 项目: MHViewer   文件: UConfigActivity.java
@Override
protected void onDestroy() {
  super.onDestroy();
  webView.destroy();

  // Put cookies back to okhttp cookie store
  CookieManager cookieManager = CookieManager.getInstance();
  String cookiesString = cookieManager.getCookie(url);

  if (cookiesString != null && !cookiesString.isEmpty()) {
    EhCookieStore store = EhApplication.getEhCookieStore(this);
    HttpUrl eUrl = HttpUrl.parse(EhUrl.HOST_E);
    HttpUrl exUrl = HttpUrl.parse(EhUrl.HOST_EX);

    // The cookies saved in the uconfig page should be shared between e and ex
    for (String header : cookiesString.split(";")) {
      Cookie eCookie = Cookie.parse(eUrl, header);
      if (eCookie != null) {
        store.addCookie(longLive(eCookie));
      }

      Cookie exCookie = Cookie.parse(exUrl, header);
      if (exCookie != null) {
        store.addCookie(longLive(exCookie));
      }
    }
  }
}
 
源代码27 项目: AndroidWallet   文件: HtmlWebViewActivity.java
@Override
protected void onDestroy() {
    CookieSyncManager.createInstance(this);  //Create a singleton CookieSyncManager within a context
    CookieManager cookieManager = CookieManager.getInstance(); // the singleton CookieManager instance
    cookieManager.removeAllCookie();// Removes all cookies.
    CookieSyncManager.getInstance().sync(); // forces sync manager to sync now
    binding.htmlWebView.setWebChromeClient(null);
    binding.htmlWebView.setWebViewClient(null);
    binding.htmlWebView.getSettings().setJavaScriptEnabled(false);
    binding.htmlWebView.destroy();
    super.onDestroy();
}
 
源代码28 项目: Android-SmartWebView   文件: MainActivity.java
public String get_cookies(String cookie){
	String value = "";
	CookieManager cookieManager = CookieManager.getInstance();
	String cookies = cookieManager.getCookie(ASWV_URL);
	String[] temp=cookies.split(";");
	for (String ar1 : temp ){
		if(ar1.contains(cookie)){
			String[] temp1=ar1.split("=");
			value = temp1[1];
			break;
		}
	}
	return value;
}
 
private void setCookies() {
        String cookieStr = CookieManager.getInstance().getCookie(mWebView.getUrl());
        if (!StringUtils.isEmpty(cookieStr)) {
            mLoginPresenter.parseCookie(cookieStr);
//            Toast.makeText(mActivity, "登陆成功", Toast.LENGTH_SHORT).show();
            if (mActivity != null) {
                mActivity.setResult(Activity.RESULT_OK);
            }
        }
    }
 
源代码30 项目: mobile-sdk-android   文件: WebviewUtil.java
public static String getCookie() {
    try {
        CookieManager cm = CookieManager.getInstance();
        if (cm == null) {
            Clog.i(Clog.httpRespLogTag, "Unable to find a CookieManager");
            return null;
        }
        return cm.getCookie(Settings.getBaseUrl());
    }catch (Exception e){
        // Catches PackageManager$NameNotFoundException for webview
        Clog.e(Clog.httpRespLogTag, "Unable to find a CookieManager - Exception: "+e.getMessage());
    }
    return null;
}