Java Code Examples for android.webkit.CookieSyncManager#startSync()

The following examples show how to use android.webkit.CookieSyncManager#startSync() . 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: ProWebView.java    From prowebview with Apache License 2.0 6 votes vote down vote up
/**
 * Clear the cookies
 */
@SuppressWarnings("deprecation")
public void clearCookies() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(getContext());
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}
 
Example 2
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 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: AdActivity.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle b) {
    super.onCreate(b);

    String activityType = getIntent().
            getStringExtra(INTENT_KEY_ACTIVITY_TYPE);
    if (StringUtil.isEmpty(activityType)) {
        Clog.e(Clog.baseLogTag, Clog.getString(R.string.adactivity_no_type));
        finish();
    } else if (ACTIVITY_TYPE_INTERSTITIAL.equals(activityType)) {
        implementation = new InterstitialAdActivity(this);
        implementation.create();
    } else if (ACTIVITY_TYPE_BROWSER.equals(activityType)) {
        implementation = new BrowserAdActivity(this);
        implementation.create();
    } else if (ACTIVITY_TYPE_MRAID.equals(activityType)) {
        implementation = new MRAIDAdActivity(this);
        implementation.create();
    }

    CookieSyncManager.createInstance(this);
    CookieSyncManager csm = CookieSyncManager.getInstance();
    if (csm != null) csm.startSync();
}
 
Example 5
Source File: WebScraper.java    From VehicleInfoOCR with GNU General Public License v3.0 5 votes vote down vote up
public void clearCookies(){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    }else{
        CookieSyncManager cookieSync = CookieSyncManager.createInstance(context);
        cookieSync.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSync.stopSync();
        cookieSync.sync();
    }
}
 
Example 6
Source File: WebViewSignInScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
public View onCreateView2(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    EhUtils.signOut(context);

    // 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(context);
        cookieSyncManager.startSync();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncManager.stopSync();
    }

    mWebView = new WebView(context);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new LoginWebViewClient());
    mWebView.loadUrl(EhUrl.URL_SIGN_IN);
    return mWebView;
}
 
Example 7
Source File: MyTagsActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 8
Source File: UConfigActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@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.getUConfigUrl();
  EhCookieStore store = EhApplication.getEhCookieStore(this);
  for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
    cookieManager.setCookie(url, cookie.toString());
  }

  setContentView(R.layout.activity_u_config);
  setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
  webView = (WebView) findViewById(R.id.webview);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new UConfigWebViewClient());
  webView.setWebChromeClient(new DialogWebChromeClient(this));
  webView.loadUrl(url);
  progress = (ProgressView) findViewById(R.id.progress);

  Snackbar.make(webView, R.string.apply_tip, Snackbar.LENGTH_LONG).show();
}
 
Example 9
Source File: ThreadViewFragment.java    From something.apk with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if(((MainActivity)getActivity()).isFragmentFocused(this)){
        threadView.onResume();
        threadView.resumeTimers();
        updateActionbarColor(forumId);
        setTitle(threadTitle);
    }
    CookieSyncManager cookieMan = CookieSyncManager.getInstance();
    if(cookieMan != null){
        cookieMan.startSync();
    }
}
 
Example 10
Source File: WebViewSignInScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
public View onCreateView2(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    EhUtils.signOut(context);

    // 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(context);
        cookieSyncManager.startSync();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncManager.stopSync();
    }

    mWebView = new WebView(context);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new LoginWebViewClient());
    mWebView.loadUrl(EhUrl.URL_SIGN_IN);
    return mWebView;
}
 
Example 11
Source File: MyTagsActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 12
Source File: UConfigActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@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.getUConfigUrl();
  EhCookieStore store = EhApplication.getEhCookieStore(this);
  for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
    cookieManager.setCookie(url, cookie.toString());
  }

  setContentView(R.layout.activity_u_config);
  setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
  webView = (WebView) findViewById(R.id.webview);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new UConfigWebViewClient());
  webView.setWebChromeClient(new DialogWebChromeClient(this));
  webView.loadUrl(url);
  progress = (ProgressView) findViewById(R.id.progress);

  Snackbar.make(webView, R.string.apply_tip, Snackbar.LENGTH_LONG).show();
}
 
Example 13
Source File: AdActivity.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    if (implementation != null) {
        WebviewUtil.onResume(implementation.getWebView());
    }
    CookieSyncManager csm = CookieSyncManager.getInstance();
    if (csm != null) csm.startSync();
    super.onResume();
}
 
Example 14
Source File: CookieUtils.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
public static void syncCookie(Context context) {
    //尼玛 获取cookie的时候先手动同步,不然会跪
    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(context);
    cookieSyncManager.startSync();
}
 
Example 15
Source File: Login.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstance);
    applyColorTheme("");
    try {
        setContentView(R.layout.activity_login);
    } catch(Exception e){
        finish();
        return;
    }
    setupAppBar(R.id.toolbar, R.string.title_login, true, true);

    String[] scopes = {
            "identity", "modcontributors", "modconfig", "modothers", "modwiki", "creddits",
            "livemanage", "account", "privatemessages", "modflair", "modlog", "report",
            "modposts", "modwiki", "read", "vote", "edit", "submit", "subscribe", "save",
            "wikiread", "flair", "history", "mysubreddits", "wikiedit"
    };
    if (Authentication.reddit == null) {
        new Authentication(getApplicationContext());
    }
    final OAuthHelper oAuthHelper = Authentication.reddit.getOAuthHelper();
    final Credentials credentials = Credentials.installedApp(CLIENT_ID, REDIRECT_URL);
    String authorizationUrl =
            oAuthHelper.getAuthorizationUrl(credentials, true, scopes).toExternalForm();
    authorizationUrl = authorizationUrl.replace("www.", "i.");
    authorizationUrl = authorizationUrl.replace("%3A%2F%2Fi", "://www");
    Log.v(LogUtil.getTag(), "Auth URL: " + authorizationUrl);
    final WebView webView = (WebView) findViewById(R.id.web);
    webView.clearCache(true);
    webView.clearHistory();
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setMinimumFontSize(1);
    webSettings.setMinimumLogicalFontSize(1);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(this);
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            LogUtil.v(url);
            if (url.contains("code=")) {
                Log.v(LogUtil.getTag(), "WebView URL: " + url);
                // Authentication code received, prevent HTTP call from being made.
                webView.stopLoading();
                new UserChallengeTask(oAuthHelper, credentials).execute(url);
                webView.setVisibility(View.GONE);
            }
        }
    });

    webView.loadUrl(authorizationUrl);
}