android.webkit.CookieSyncManager Java Examples

The following examples show how to use android.webkit.CookieSyncManager. 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: WebViewUtil.java    From Huochexing12306 with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #2
Source File: ProfileEditFragment.java    From 4pdaClient-plus with Apache License 2.0 6 votes vote down vote up
protected void onPostExecute(final Boolean success) {
    setLoading(false);

    if (isCancelled()) return;

    if (success) {
        showThemeBody(m_ThemeBody);
    } else {
        getSupportActionBar().setTitle(ex.getMessage());
        m_WebView.loadDataWithBaseURL("https://4pda.ru/forum/", m_ThemeBody, "text/html", "UTF-8", null);
        AppLog.e(getMainActivity(), ex);
    }

    CookieSyncManager syncManager = CookieSyncManager.createInstance(m_WebView.getContext());
    CookieManager cookieManager = CookieManager.getInstance();

        for (HttpCookie cookie : Client.getInstance().getCookies()) {

            if (cookie.getDomain() != null) {
                cookieManager.setCookie(cookie.getDomain(), cookie.getName() + "=" + cookie.getValue());
            }
            //cookieManager.setCookie(cookie.getTitle(),cookie.getValue());
        }
    syncManager.sync();
}
 
Example #3
Source File: Cookies.java    From DelegateAdapter with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
    public static void clearCookies(Context context) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            //Log.d(C.TAG, "Using clearCookies code for API >=" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
        } else {
//            Log.d(C.TAG, "Using clearCookies code for API <" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
            CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context);
            cookieSyncMngr.startSync();
            CookieManager cookieManager=CookieManager.getInstance();
            cookieManager.removeAllCookie();
            cookieManager.removeSessionCookie();
            cookieSyncMngr.stopSync();
            cookieSyncMngr.sync();
        }
    }
 
Example #4
Source File: InsLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 6 votes vote down vote up
@Override
public void recycle() {

    //清空所有Cookie
    CookieSyncManager.createInstance(mActivity);  //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

    mWebView.setWebChromeClient(null);
    mWebView.setWebViewClient(null);
    mWebView.getSettings().setJavaScriptEnabled(false);
    mWebView.clearCache(true);

    webParentView.removeAllViews();
    mWebView = null;
    mClientSecret = null;
    mClientId = null;
    super.recycle();
}
 
Example #5
Source File: AuthorizationClient.java    From HypFacebook with BSD 2-Clause "Simplified" License 6 votes vote down vote up
void onWebDialogComplete(AuthorizationRequest request, Bundle values,
        FacebookException error) {
    Result outcome;
    if (values != null) {
        AccessToken token = AccessToken
                .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW);
        outcome = Result.createTokenResult(token);

        // Ensure any cookies set by the dialog are saved
        // 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();
        saveCookieToken(token.getToken());
    } else {
        if (error instanceof FacebookOperationCanceledException) {
            outcome = Result.createCancelResult("User canceled log in.");
        } else {
            outcome = Result.createErrorResult(error.getMessage(), null);
        }
    }
    completeAndValidate(outcome);
}
 
Example #6
Source File: VKSdk.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
/**
 * Wipes out information about the access token and clears cookies for internal browse
 */
@SuppressLint("NewApi")
public static void logout() {
    Context context = VKUIHelper.getApplicationContext();
    if (Build.VERSION.SDK_INT < 21) {
        CookieSyncManager.createInstance(context);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
    } else {
        CookieManager.getInstance().removeAllCookies(null);
    }

    VKAccessToken.replaceToken(VKUIHelper.getApplicationContext(), null);

    updateLoginState(context);
}
 
Example #7
Source File: TyApplication.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    mContext = this;

    initDagger();
    initDb();
    initDownload();
    initUtils();
    initEditor();
    initBitFrame();
    initUploading();
    initVideo();
    initCache();

    if (UserCache.getDefault() != null) {
        Crashlytics.setUserIdentifier(UserCache.getDefault().getAccountId() + "");
    }

    CookieSyncManager.createInstance(this);
}
 
Example #8
Source File: AuthCookie.java    From utexas-utilities with Apache License 2.0 6 votes vote down vote up
protected void setAuthCookieVal(String authCookie, String domain) {
    this.authCookie = authCookie;
    settings.edit().putString(prefKey, authCookie).apply();

    /*
    this is technically unnecessary if OkHttp handled the authentication, because it will
    have already set the cookies in the CookieHandler. It doesn't seem to cause any issues
    just to re-add the cookies, though
     */
    HttpCookie httpCookie = new HttpCookie(authCookieKey, authCookie);
    httpCookie.setDomain(domain);
    try {
        CookieStore cookies = ((CookieManager) CookieHandler.getDefault()).getCookieStore();
        cookies.add(URI.create(domain), httpCookie);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
    cookieHasBeenSet = true;
    android.webkit.CookieManager.getInstance().setCookie(domain, httpCookie.getName() + "=" + httpCookie.getValue());
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        android.webkit.CookieManager.getInstance().flush();
    } else {
        CookieSyncManager.getInstance().sync();
    }
}
 
Example #9
Source File: AuthorizationClient.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 6 votes vote down vote up
void onWebDialogComplete(AuthorizationRequest request, Bundle values,
        FacebookException error) {
    Result outcome;
    if (values != null) {
        AccessToken token = AccessToken
                .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW);
        outcome = Result.createTokenResult(token);

        // Ensure any cookies set by the dialog are saved
        // 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();
        saveCookieToken(token.getToken());
    } else {
        if (error instanceof FacebookOperationCanceledException) {
            outcome = Result.createCancelResult("User canceled log in.");
        } else {
            outcome = Result.createErrorResult(error.getMessage(), null);
        }
    }
    completeAndValidate(outcome);
}
 
Example #10
Source File: Utility.java    From platform-friends-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
}
 
Example #11
Source File: InAppBrowser.java    From ultimate-cordova-webview-app with MIT License 6 votes vote down vote up
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");
    }
}
 
Example #12
Source File: BaseWebView.java    From dcs-sdk-java with Apache License 2.0 6 votes vote down vote up
private void setCookie(Context context, String domain, String sessionCookie) {
    CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    if (sessionCookie != null) {
        // delete old cookies
        cookieManager.removeSessionCookie();
    }
    try {
        Thread.sleep(200);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    cookieManager.setCookie(domain, sessionCookie);

    CookieSyncManager.createInstance(context);
    CookieSyncManager.getInstance().sync();
}
 
Example #13
Source File: WebViewUtils.java    From android-auth with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #14
Source File: EvernoteSession.java    From EverMemo-EverNote with MIT License 6 votes vote down vote up
/**
 * Clear all stored authentication information.
 */
public void logOut(Context ctx) throws InvalidAuthenticationException {
  if(!isLoggedIn()) {
    throw new InvalidAuthenticationException("Must not call when already logged out");
  }
  synchronized (this) {
    mAuthenticationResult.clear(SessionPreferences.getPreferences(ctx));
    mAuthenticationResult = null;
  }

  // TODO The cookie jar is application scope, so we should only be removing
  // evernote.com cookies.
  CookieSyncManager.createInstance(ctx);
  CookieManager cookieManager = CookieManager.getInstance();
  cookieManager.removeAllCookie();
}
 
Example #15
Source File: TwitterDialog.java    From NewAndroidTwitter with Apache License 2.0 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView() {
   	CookieSyncManager.createInstance(getContext()); 
       CookieManager cookieManager = CookieManager.getInstance();
       cookieManager.removeAllCookie();
       
       mWebView = new WebView(getContext());
       
       mWebView.setVerticalScrollBarEnabled(false);
       mWebView.setHorizontalScrollBarEnabled(false);
       mWebView.setWebViewClient(new TwitterWebViewClient());
       mWebView.getSettings().setJavaScriptEnabled(true);
       mWebView.loadUrl(mUrl);
       mWebView.setLayoutParams(FILL);
       
       mContent.addView(mWebView);
   }
 
Example #16
Source File: a.java    From letv with Apache License 2.0 6 votes vote down vote up
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 #17
Source File: ANJAMImplementation.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
private static void callRecordEvent(AdWebView webView, Uri uri) {
    String urlParam = uri.getQueryParameter("url");

    if ((urlParam == null)
            || (!urlParam.startsWith("http"))) {
        return;
    }

    // Create a invisible webview to fire the url
    WebView recordEventWebView = new WebView(webView.getContext());
    recordEventWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            Clog.d(Clog.baseLogTag, "RecordEvent completed loading: " + url);

            CookieSyncManager csm = CookieSyncManager.getInstance();
            if (csm != null) csm.sync();
        }
    });
    recordEventWebView.loadUrl(urlParam);
    recordEventWebView.setVisibility(View.GONE);
    webView.addView(recordEventWebView);
}
 
Example #18
Source File: InstagramDialog.java    From social-login-helper-Deprecated- with MIT License 6 votes vote down vote up
@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();
}
 
Example #19
Source File: Util.java    From CoolApk-Console with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @see <a href="http://stackoverflow.com/questions/28998241/how-to-clear-cookies-and-cache-of-webview-on-android-when-not-in-webview" />
 * @param context
 */
@SuppressWarnings("deprecation")
public static void clearCookies(Context context)
{

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else
    {
        CookieSyncManager cookieSyncMngr= CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager= CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}
 
Example #20
Source File: FacebookLoginActivity.java    From facebooklogin with MIT License 6 votes vote down vote up
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();
}
 
Example #21
Source File: HttpTask.java    From letv with Apache License 2.0 6 votes vote down vote up
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 #22
Source File: Utility.java    From KlyphMessenger with MIT License 6 votes vote down vote up
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();
}
 
Example #23
Source File: PrebidServerAdapter.java    From prebid-mobile-android with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #24
Source File: InAppBrowser.java    From AvI with MIT License 6 votes vote down vote up
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();
    }

    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");
    }
}
 
Example #25
Source File: InstagramSession.java    From AndroidInstagram with Apache License 2.0 6 votes vote down vote up
/**
 * Reset user data
 */
public void reset() {
	Editor editor = mSharedPref.edit();
	
	editor.putString(ACCESS_TOKEN, 	"");
	editor.putString(USERID, 		"");
	editor.putString(USERNAME, 		"");
	editor.putString(FULLNAME, 		"");
	editor.putString(PROFILPIC, 	"");
	
	editor.commit();
	
	CookieSyncManager.createInstance(mContext);
	
	CookieManager cookieManager = CookieManager.getInstance();
	cookieManager.removeAllCookie();
}
 
Example #26
Source File: MainActivity.java    From Lucid-Browser with Apache License 2.0 6 votes vote down vote up
/**
	 * 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
    }
 
Example #27
Source File: EdxCookieManager.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
public static synchronized EdxCookieManager getSharedInstance(@NonNull final Context context) {
    if ( instance == null ) {
        instance = new EdxCookieManager();
        RoboGuice.getInjector(context).injectMembers(instance);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            CookieSyncManager.createInstance(context);
        }
    }
    return instance;
}
 
Example #28
Source File: HuPuWebView.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
private void init() {
    WebSettings settings = getSettings();
    settings.setBuiltInZoomControls(false);
    settings.setSupportZoom(false);
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setSupportMultipleWindows(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setDomStorageEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setUseWideViewPort(true);
    if (Build.VERSION.SDK_INT > 6) {
        settings.setAppCacheEnabled(true);
        settings.setLoadWithOverviewMode(true);
    }
    String path = getContext().getFilesDir().getPath();
    settings.setGeolocationEnabled(true);
    settings.setGeolocationDatabasePath(path);
    settings.setDomStorageEnabled(true);
    this.basicUA = settings.getUserAgentString() + " kanqiu/7.05.6303/7059";
    setBackgroundColor(0);
    initWebViewClient();
    setWebChromeClient(new HuPuChromeClient());
    try {
        if (SettingPrefUtils.isLogin()) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "u=" + SettingPrefUtils.getCookies());
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_gamesu=" + URLEncoder.encode(SettingPrefUtils.getToken(), "utf-8"));
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_inKanqiuApp=1");
            cookieManager.setCookie("http://bbs.mobileapi.hupu.com", "_kanqiu=1");
            CookieSyncManager.getInstance().sync();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #29
Source File: SDK2APPReceiver.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example #30
Source File: IncognitoActivity.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Completable updateCookiePreference() {
    return Completable.create(new CompletableAction() {
        @Override
        public void onSubscribe(@NonNull CompletableSubscriber subscriber) {
            CookieManager cookieManager = CookieManager.getInstance();
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                CookieSyncManager.createInstance(IncognitoActivity.this);
            }
            cookieManager.setAcceptCookie(mPreferences.getIncognitoCookiesEnabled());
            subscriber.onComplete();
        }
    });
}