Java Code Examples for android.webkit.CookieManager#setAcceptCookie()
The following examples show how to use
android.webkit.CookieManager#setAcceptCookie() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From Android-SmartWebView with MIT License | 7 votes |
public String get_location(){ String newloc = "0,0"; //Checking for location permissions if (ASWP_LOCATION && (Build.VERSION.SDK_INT < 23 || check_permission(1))) { GPSTrack gps; gps = new GPSTrack(MainActivity.this); double latitude = gps.getLatitude(); double longitude = gps.getLongitude(); if (gps.canGetLocation()) { if (latitude != 0 || longitude != 0) { if(true_online) { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setCookie(ASWV_URL, "lat=" + latitude); cookieManager.setCookie(ASWV_URL, "long=" + longitude); } //Log.w("New Updated Location:", latitude + "," + longitude); //enable to test dummy latitude and longitude newloc = latitude+","+longitude; } else { Log.w("New Updated Location:", "NULL"); } } else { show_notification(1, 1); Log.w("New Updated Location:", "FAIL"); } } return newloc; }
Example 2
Source File: CookieUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
public static void setCookieFromCookieStore(Context context, String url) { syncCookie(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); List<Cookie> cookies = getCookies(context); Log.e("cookies", "cookies.size:" + cookies.size()); if (!cookies.isEmpty()) { for (int i = 0; i < cookies.size(); i++) { Cookie cookie = cookies.get(i); String cookieStr = cookie.getName() + "=" + cookie.getValue() + ";" + "expiry=" + cookie.getExpiryDate() + ";" + "domain=" + cookie.getDomain() + ";" + "path=/"; cookieManager.setCookie(url, cookieStr);//cookies是在HttpClient中获得的cookie } } }
Example 3
Source File: HttpTask.java From letv with Apache License 2.0 | 6 votes |
protected void sendResponseMessage(HttpResponse response) { super.sendResponseMessage(response); Header[] headers = response.getHeaders("Set-Cookie"); if (headers != null && headers.length > 0) { CookieSyncManager.createInstance(this.val$context).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.THIRDLOGIN, split[1]); int index = split[1].indexOf(";"); if (TextUtils.isEmpty(mm)) { mm = split[1].substring(index + 1); EALogger.i("正式登录", "mm===>" + mm); } } EALogger.i("正式登录", "split[1222]===>COOKIE_DEVICE_ID=" + LemallPlatform.getInstance().uuid + ";" + mm); instance.setCookie(Constants.THIRDLOGIN, "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(); } }
Example 4
Source File: HttpTask.java From letv with Apache License 2.0 | 6 votes |
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(); } }
Example 5
Source File: a.java From letv with Apache License 2.0 | 6 votes |
public static void a(Context context, String str, String str2, String str3, String str4) { if (!TextUtils.isEmpty(str)) { CookieSyncManager.createInstance(context); CookieManager instance = CookieManager.getInstance(); instance.setAcceptCookie(true); String str5 = null; if (Uri.parse(str).getHost().toLowerCase().endsWith(".qq.com")) { str5 = ".qq.com"; } instance.setCookie(str, b("logintype", "MOBILEQ", str5)); instance.setCookie(str, b("qopenid", str2, str5)); instance.setCookie(str, b("qaccesstoken", str3, str5)); instance.setCookie(str, b("openappid", str4, str5)); CookieSyncManager.getInstance().sync(); } }
Example 6
Source File: SyncUserStateUtil.java From letv with Apache License 2.0 | 5 votes |
public static void setGameTokenCookie(Context context, String token) { CookieSyncManager syncManger = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setCookie("http://api.game.letvstore.com", "sso_tk=" + token); syncManger.sync(); LogInfo.log("wlx", "game cookie = " + cookieManager.getCookie("http://api.game.letvstore.com")); }
Example 7
Source File: WebViewActivity.java From mattermost-android-classic with Apache License 2.0 | 5 votes |
protected void initWebView(WebView view) { webView = view; setProgressBarVisibility(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } WebSettings settings = view.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setUserAgentString(settings.getUserAgentString() + " Web-Atoms-Mobile-WebView"); settings.setDatabaseEnabled(true); settings.setMediaPlaybackRequiresUserGesture(false); final File dir = this.getExternalCacheDir(); settings.setAppCacheMaxSize(1024*1024*20); settings.setAppCachePath(dir.getAbsolutePath()); settings.setAllowFileAccess(true); settings.setAppCacheEnabled(true); settings.setCacheMode(WebSettings.LOAD_DEFAULT); view.setDownloadListener(getDownloadListener()); CookieManager cookies = CookieManager.getInstance(); cookies.setAcceptCookie(true); setWebViewClient(view); setWebChromeClient(view); }
Example 8
Source File: TopSlidWebView.java From MyBlogDemo with Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") private void setCookie(String url) { URI uri = URI.create(url); if (TextUtils.isEmpty(uri.getHost())) { return; } if (Build.VERSION.SDK_INT < 21) { CookieSyncManager.createInstance(getContext()); } CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie(); // 注入cookies List<String> cookies = getCookies(); for (String cookie : cookies) { cookieManager.setCookie(uri.getHost(), cookie); } if (Build.VERSION.SDK_INT >= 21) { cookieManager.flush(); } else { CookieSyncManager.getInstance().sync(); } }
Example 9
Source File: WebViewActivity.java From CloudReader with Apache License 2.0 | 5 votes |
/** * 同步cookie */ private void syncCookie(String url) { if (!TextUtils.isEmpty(url) && url.contains("wanandroid")) { try { CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie();// 移除 cookieManager.removeAllCookie(); String cookie = SPUtils.getString("cookie", ""); if (!TextUtils.isEmpty(cookie)) { String[] split = cookie.split(";"); for (int i = 0; i < split.length; i++) { cookieManager.setCookie(url, split[i]); } } // String cookies = cookieManager.getCookie(url); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.flush(); } else { CookieSyncManager.getInstance().sync(); } } catch (Exception e) { DebugUtil.error("==异常==", e.toString()); } } }
Example 10
Source File: MainActivity.java From Android-SmartWebView with MIT License | 5 votes |
public void get_info(){ if(true_online) { fcm_token(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setCookie(ASWV_URL, "DEVICE=android"); cookieManager.setCookie(ASWV_URL, "DEV_API=" + Build.VERSION.SDK_INT); Log.d("COOKIES: ", cookieManager.getCookie(ASWV_URL)); } }
Example 11
Source File: LetvUtils.java From letv with Apache License 2.0 | 5 votes |
public static void setCookies(Context context, String url) { String cookie1 = "letvclient_sig=" + MD5.toMd5(Global.DEVICEID + LetvConstant.MIYUE_ATTENDANCE); String cookie2 = "letvclient_did=" + Global.DEVICEID; CookieSyncManager syncManger = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); String CookieStr = cookieManager.getCookie(url); if (CookieStr == null || !CookieStr.contains("letvclient_did") || !CookieStr.contains("letvclient_sig")) { cookieManager.setAcceptCookie(true); cookieManager.setCookie(url, cookie1); cookieManager.setCookie(url, cookie2); syncManger.sync(); } }
Example 12
Source File: LogonManager.java From letv with Apache License 2.0 | 5 votes |
public void deleteCookie() { CookieSyncManager.createInstance(this.context).sync(); CookieManager instance = CookieManager.getInstance(); instance.setAcceptCookie(true); instance.removeAllCookie(); LemallPlatform.getInstance().setCookieLinkdata(""); System.gc(); }
Example 13
Source File: QuickUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 给webview设置cookie * * @param context * @param url */ public static void setCookies(Context context, String url) { if (!TextUtils.isEmpty(url)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){ CookieSyncManager.createInstance( context); } CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie(); // 自动注入cookie,这个在使用cookie作为用户校验时有用 cookieManager.setCookie(url, "JSESSIONID=" + QuickUtil.getToken()); CookieSyncManager.getInstance().sync(); } }
Example 14
Source File: ProgressWebView.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
/** * 设置当前登录用户的cookie信息 * @param context * @return */ public void webViewSetCookie(Context context, String url) { //设置cookie String domain = StringUtil.getTopDomain(url); XLog.debug("domain:"+domain); String cookie = "x-token="+ O2SDKManager.Companion.instance().getZToken(); XLog.debug("cookie:"+cookie); String host = APIAddressHelper.Companion.instance().getWebViewHost(); XLog.debug("host:"+host); String cookieStr; if (StringUtil.isIp(host)){ cookieStr = cookie; }else { cookieStr = cookie +"; path=/; domain=."+domain; } XLog.debug("Set-Cookie:"+cookieStr); CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setCookie(url, cookieStr); CookieSyncManager.getInstance().sync(); String newCookie = cookieManager.getCookie(url); if(newCookie != null){ XLog.debug("Nat: webView.syncCookie.newCookie "+newCookie); } XLog.debug("mCookieManager is finish"); }
Example 15
Source File: PadViewActivity.java From padland with Apache License 2.0 | 5 votes |
/** * onCreate override * * @param savedInstanceState */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent myIntent = getIntent(); if (myIntent.getExtras() == null) { finish(); return; } // Checks if the url is a valid pad this._makePadUrl(); handler = new Handler(); // If no network... if (!isNetworkAvailable()) { Toast.makeText(this, getString(R.string.network_is_unreachable), Toast.LENGTH_LONG).show(); return; } setContentView(R.layout.activity_padview); _loadProgressWheel(); this._saveNewPad(); this._updateViewedPad(); this._makeWebView(); // Cookies will be needed for pads CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.setAcceptThirdPartyCookies(webView, true); } // Load it! loadUrl(current_padUrl); }
Example 16
Source File: ChatWindowView.java From chat-window-android with MIT License | 4 votes |
private void initView(Context context) { setFitsSystemWindows(true); setVisibility(GONE); LayoutInflater.from(context).inflate(R.layout.view_chat_window_internal, this, true); webView = (WebView) findViewById(R.id.chat_window_web_view); statusText = (TextView) findViewById(R.id.chat_window_status_text); progressBar = (ProgressBar) findViewById(R.id.chat_window_progress); reloadButton = (Button) findViewById(R.id.chat_window_button); reloadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { reload(); } }); if (Build.VERSION.RELEASE.matches("4\\.4(\\.[12])?")) { String userAgentString = webView.getSettings().getUserAgentString(); webView.getSettings().setUserAgentString(userAgentString + " AndroidNoFilesharing"); } CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); webView.setFocusable(true); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setAppCacheEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setSupportMultipleWindows(true); webSettings.setDomStorageEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.getInstance().setAcceptThirdPartyCookies(webView, true); } webView.setWebViewClient(new LCWebViewClient()); webView.setWebChromeClient(new LCWebChromeClient()); webView.requestFocus(View.FOCUS_DOWN); webView.setVisibility(GONE); webView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); webView.addJavascriptInterface(new ChatWindowJsInterface(this), ChatWindowJsInterface.BRIDGE_OBJECT_NAME); }
Example 17
Source File: TyWebViewCookie.java From tysq-android with GNU General Public License v3.0 | 4 votes |
public static CookieManager getInstance() { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); return cookieManager; }
Example 18
Source File: SamlWebViewDialog.java From Cirrus_depricated with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("deprecation") @SuppressLint("SetJavaScriptEnabled") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log_OC.v(TAG, "onCreateView, savedInsanceState is " + savedInstanceState); // Inflate layout of the dialog RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.sso_dialog, container, false); // null parent view because it will go in the dialog layout if (mSsoWebView == null) { // initialize the WebView mSsoWebView = new SsoWebView(getActivity().getApplicationContext()); mSsoWebView.setFocusable(true); mSsoWebView.setFocusableInTouchMode(true); mSsoWebView.setClickable(true); WebSettings webSettings = mSsoWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(false); webSettings.setLoadWithOverviewMode(false); webSettings.setSavePassword(false); webSettings.setUserAgentString(MainApp.getUserAgent()); webSettings.setSaveFormData(false); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeAllCookie(); mSsoWebView.loadUrl(mInitialUrl); } mWebViewClient.setTargetUrl(mTargetUrl); mSsoWebView.setWebViewClient(mWebViewClient); // add the webview into the layout RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT ); ssoRootView.addView(mSsoWebView, layoutParams); ssoRootView.requestLayout(); return ssoRootView; }
Example 19
Source File: ThreadViewFragment.java From something.apk with MIT License | 4 votes |
@Override public void viewCreated(View frag, Bundle savedInstanceState) { navPrev = (ImageView) frag.findViewById(R.id.threadview_prev); navNext = (ImageView) frag.findViewById(R.id.threadview_next); navPageBar = (TextView) frag.findViewById(R.id.threadview_page); navPageBar.setOnClickListener(this); navNext.setOnClickListener(this); navPrev.setOnClickListener(this); pfbContainer = frag.findViewById(R.id.threadview_pullfrombottom); pfbTitle = (TextView) frag.findViewById(R.id.threadview_pullfrombottom_title); pfbProgressbar = (ProgressBar) frag.findViewById(R.id.threadview_pullfrombottom_progress); threadView = (WebView) frag.findViewById(R.id.ptr_webview); initWebview(); updateNavbar(); CookieManager cookieManager = CookieManager.getInstance(); if (!SomeUtils.isLollipop()) { CookieSyncManager.createInstance(getContext()); } cookieManager.setAcceptCookie(true); cookieManager.setCookie(Constants.COOKIE_DOMAIN, SomePreferences.getCookie(Constants.COOKIE_USER_ID)); cookieManager.setCookie(Constants.COOKIE_DOMAIN, SomePreferences.getCookie(Constants.COOKIE_USER_PASS)); cookieManager.setCookie(Constants.COOKIE_DOMAIN, SomePreferences.getCookie(Constants.COOKIE_SESSION_HASH)); cookieManager.setCookie(Constants.COOKIE_DOMAIN, SomePreferences.getCookie(Constants.COOKIE_SESSION_ID)); if (!SomeUtils.isLollipop()) { CookieSyncManager.getInstance().sync(); } if(savedInstanceState != null && savedInstanceState.containsKey("thread_html")){ loadThreadState(savedInstanceState); }else{ Intent intent = getActivity().getIntent(); threadId = intent.getIntExtra("thread_id", 0); page = intent.getIntExtra("thread_page", 0); postId = intent.getLongExtra("post_id", 0); if(threadId > 0 || postId > 0){ setTitle("Loading..."); startRefresh(); } } }
Example 20
Source File: QunarWebActvity.java From imsdk-android with MIT License | 4 votes |
public void synCookie() { //下面的变量都是暂时处理 日后逻辑清晰重新构成 Boolean isHistory = mUrl.contains("main_controller"); CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); if (isHistory) { cookieManager.removeAllCookie(); } if (from != null && from.equals(Constants.BundleValue.UC_LOGIN)) { cookieManager.removeAllCookie(); } if (!TextUtils.isEmpty(mUrl) && mUrl.contains(DOMAIN)) { String qvtStr = CurrentPreference.getInstance().getQvt(); boolean qvt = false; if (!TextUtils.isEmpty(qvtStr) && !isHistory) { QVTResponseResult qvtResponseResult = JsonUtils.getGson().fromJson(qvtStr, QVTResponseResult.class); if (qvtResponseResult.ret) { cookieManager.setCookie(DOMAIN, "_v=" + qvtResponseResult.data.vcookie + ";"); cookieManager.setCookie(DOMAIN, "_t=" + qvtResponseResult.data.tcookie + ";"); cookieManager.setCookie(DOMAIN, "_q=" + qvtResponseResult.data.qcookie + ";"); cookieManager.setCookie(DOMAIN, "q_d=" + QtalkNavicationService.getInstance().getXmppdomain() + ";"); qvt = true; } } // if (!isHistory) { // if (!qvt) { // cookieManager.setCookie(DOMAIN, "_v=;"); // cookieManager.setCookie(DOMAIN, "_t=;"); // cookieManager.setCookie(DOMAIN, "_q=;"); // cookieManager.setCookie(DOMAIN, "q_d=;"); // } // } } if (mUrl.contains("/package/plts/dashboard")) { cookieManager.setCookie(DOMAIN, "q_u=" + CurrentPreference.getInstance().getUserid() + ";"); cookieManager.setCookie(DOMAIN, "q_nm=" + CurrentPreference.getInstance().getUserid() + ";"); cookieManager.setCookie(DOMAIN, "q_d=" + QtalkNavicationService.getInstance().getXmppdomain() + ";"); } if(isVideoAudioCall){ cookieManager.setCookie(DOMAIN, "_caller=" + QtalkStringUtils.parseId(videoCaller) + ";"); cookieManager.setCookie(DOMAIN, "_callee=" + QtalkStringUtils.parseId(videoCallee) + ";"); cookieManager.setCookie(DOMAIN, "_calltime=" + System.currentTimeMillis() + ";"); cookieManager.setCookie(DOMAIN, "u=" + CurrentPreference.getInstance().getUserid() + ";"); }else { cookieManager.setCookie(DOMAIN, "_caller=;"); cookieManager.setCookie(DOMAIN, "_callee=;"); cookieManager.setCookie(DOMAIN, "_calltime=;"); cookieManager.setCookie(DOMAIN, "u=;"); } //默认种qckey cookieManager.setCookie(DOMAIN, "q_ckey=" + Protocol.getCKEY() + ";"); if (QtalkSDK.getInstance().isLoginStatus()) { cookieManager.setCookie(DOMAIN, "_u=" + CurrentPreference.getInstance().getUserid() + ";"); cookieManager.setCookie(DOMAIN, "q_u=" + CurrentPreference.getInstance().getUserid() + ";"); cookieManager.setCookie(DOMAIN, "_k=" + CurrentPreference.getInstance().getVerifyKey() + ";"); cookieManager.setCookie(DOMAIN, "q_d=" + QtalkNavicationService.getInstance().getXmppdomain() + ";"); } else { cookieManager.setCookie(DOMAIN, "_u=;"); cookieManager.setCookie(DOMAIN, "_k=;"); cookieManager.setCookie(DOMAIN, "q_d=;"); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { cookieManager.flush(); } else { CookieSyncManager.getInstance().sync(); } Logger.i("QunarWebActvity getCookie:"+ cookieManager.getCookie(DOMAIN)); }