Java Code Examples for android.webkit.CookieManager#setAcceptThirdPartyCookies()

The following examples show how to use android.webkit.CookieManager#setAcceptThirdPartyCookies() . 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: PadViewActivity.java    From padland with Apache License 2.0 5 votes vote down vote up
/**
 * 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 2
Source File: WebviewUtil.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to set generic WebView settings
 *
 * @param webView webView to apply settings to
 */
@SuppressLint("SetJavaScriptEnabled")
public static void setWebViewSettings(WebView webView) {
    try {
        if (webView == null) {
            return;
        }
        webView.getSettings().setBuiltInZoomControls(false);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setJavaScriptEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        webView.getSettings().setDomStorageEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
        }
        webView.getSettings().setAllowFileAccess(false);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            webView.getSettings().setAllowContentAccess(false);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            webView.getSettings().setAllowFileAccessFromFileURLs(false);
            webView.getSettings().setAllowUniversalAccessFromFileURLs(false);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            CookieManager cm = CookieManager.getInstance();
            if (cm != null) {
                cm.setAcceptThirdPartyCookies(webView, true);
            } else {
                Clog.d(Clog.baseLogTag, "Failed to set Webview to accept 3rd party cookie");
            }
        }
    }catch (Exception e){
        // Catches PackageManager$NameNotFoundException for webview
        Clog.e(Clog.httpRespLogTag, "Unable update webview settings - Exception: "+e.getMessage());
    }
}
 
Example 3
Source File: MainActivity.java    From chromium-webview-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to set some generic defaults for a
 * given WebView
 *
 * @param webView
 */
@TargetApi(Build.VERSION_CODES.L)
private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

    // Allow use of Local Storage
    settings.setDomStorageEnabled(true);

    if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }

    // Enable remote debugging via chrome://inspect
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    webView.setWebViewClient(new WebViewClient());

    // AppRTC requires third party cookies to work
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptThirdPartyCookies(mWebRTCWebView, true);
}
 
Example 4
Source File: WebViewPresenter.java    From qvod with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // 网页内容的宽度是否可大于WebView控件的宽度
    settings.setLoadWithOverviewMode(false);
    // 保存表单数据
    settings.setSaveFormData(true);
    // 是否应该支持使用其屏幕缩放控件和手势缩放
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    // 启动应用缓存
    settings.setAppCacheEnabled(true);
    // 设置缓存模式
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    // setDefaultZoom  api19被弃用
    // 设置此属性,可任意比例缩放。
    settings.setUseWideViewPort(true);
    // 缩放比例 1
    webView.setInitialScale(1);
    // 告诉WebView启用JavaScript执行。默认的是false。
    settings.setJavaScriptEnabled(true);
    //  页面加载好以后,再放开图片
    settings.setBlockNetworkImage(false);
    // 使用localStorage则必须打开
    settings.setDomStorageEnabled(true);
    // 排版适应屏幕
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    // WebView是否支持多个窗口。
    settings.setSupportMultipleWindows(true);

    // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    /** 设置字体默认缩放大小(改变网页字体大小,setTextSize  api14被弃用)*/
    settings.setTextZoom(100);

    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    // AppRTC requires third party cookies to work
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptThirdPartyCookies(webView, true);


}
 
Example 5
Source File: NestedWebview.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
@SuppressLint({"SetJavaScriptEnabled"})
public void initializeSettings(){
    boolean isTablet = getResources().getBoolean(R.bool.isTablet);
    String lang = Locale.getDefault().getDisplayLanguage();
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.setAcceptThirdPartyCookies(NestedWebview.this, true);
    WebSettings mWebSettings = getSettings();
    mWebSettings.setJavaScriptEnabled(true);
    mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    mWebSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
    mWebSettings.setBuiltInZoomControls(true);
    mWebSettings.setDisplayZoomControls(false);
    mWebSettings.setMediaPlaybackRequiresUserGesture(false);
    if(isTablet){
        mWebSettings.setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Simplicity/57.0.3098.116");
        mWebSettings.setLoadWithOverviewMode(true);
        mWebSettings.setUseWideViewPort(true);
    }else{
        mWebSettings.setUserAgentString(null);
        mWebSettings.setLoadWithOverviewMode(true);
        mWebSettings.setUseWideViewPort(true);
    }
    mWebSettings.setAppCacheEnabled(true);
    mWebSettings.setDatabaseEnabled(true);
    if (UserPreferences.getBoolean("enable_location", false)) {
        mWebSettings.setGeolocationEnabled(true);
    } else {
        mWebSettings.setGeolocationEnabled(false);
    }
    if(UserPreferences.getBoolean("lite_mode", false)){
        mWebSettings.setLoadsImagesAutomatically(false);
    }else{
        mWebSettings.setLoadsImagesAutomatically(true);
    }
    mWebSettings.setAllowFileAccessFromFileURLs(true);
    mWebSettings.setAllowUniversalAccessFromFileURLs(true);
    mWebSettings.setDomStorageEnabled(true);
    mWebSettings.setTextZoom(Integer.parseInt(UserPreferences.getInstance(WEB_ACTIVITY).getFont()));
    addJavascriptInterface(new ReaderHandler(SimplicityApplication.getContextOfApplication(), MainActivity.getMainActivity()), "simplicity_reader");
    if(UserPreferences.getBoolean("facebook_photos", false)){
        addJavascriptInterface(new ImageInterface(WEB_ACTIVITY), "Photos");
    }

}
 
Example 6
Source File: CommonRefreshWebViewActivity.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
/**
     * 子类如果对WebSetting 有自己的设置,则重写此方法
     */
    @SuppressLint("NewApi")
    protected void forwardInitWebViewAndWebSettings() {
        if (!Util.isCompateApi(16) && Util.isCompateApi(11)) {//android 4.1以下(不含4.1)
            webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        webView.setHorizontalScrollBarEnabled(false);
        webView.setVerticalScrollBarEnabled(false);
        WebSettings webSettings = webView.getSettings();

        webSettings.setSavePassword(false);
        webSettings.setAppCacheEnabled(true);

        // Enable Javascript
        webSettings.setJavaScriptEnabled(true);

        // Enable pinch to zoom without the zoom buttons
        webSettings.setBuiltInZoomControls(true);

        if (Build.VERSION.SDK_INT > 11) {
            // Hide the zoom controls for HONEYCOMB+
            webSettings.setDisplayZoomControls(false);
        }
//        webSettings.setSupportZoom(true);

        // Use WideViewport and Zoom out if there is no viewport defined
        webSettings.setUseWideViewPort(true);//设置此属性,可任意比例缩放
        webSettings.setLoadWithOverviewMode(true);

        // Allow use of Local Storage
        webSettings.setDomStorageEnabled(true);


        // Enable remote debugging via chrome://inspect
        if(Build.VERSION.SDK_INT >= 19) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);


        // AppRTC requires third party cookies to work
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView, true);
    }
 
Example 7
Source File: VideoWebView.java    From mobile-sdk-android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
protected void setupSettings() {
    Settings.getSettings().ua = this.getSettings().getUserAgentString();
    this.getSettings().setJavaScriptEnabled(true);
    this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    this.getSettings().setBuiltInZoomControls(false);
    this.getSettings().setLightTouchEnabled(false);
    this.getSettings().setLoadsImagesAutomatically(true);
    this.getSettings().setSupportZoom(false);
    this.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    this.getSettings().setUseWideViewPort(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        this.getSettings().setMediaPlaybackRequiresUserGesture(false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        this.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
    this.getSettings().setAllowFileAccess(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        this.getSettings().setAllowContentAccess(false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        this.getSettings().setAllowFileAccessFromFileURLs(false);
        this.getSettings().setAllowUniversalAccessFromFileURLs(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager cm = CookieManager.getInstance();
        if (cm != null) {
            cm.setAcceptThirdPartyCookies(this, true);
        } else {
            Clog.d(Clog.videoLogTag, "Failed to set Webview to accept 3rd party cookie");
        }
    }

    setHorizontalScrollbarOverlay(false);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollbarOverlay(false);
    setVerticalScrollBarEnabled(false);


    setBackgroundColor(Color.TRANSPARENT);
    setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
}
 
Example 8
Source File: AdWebView.java    From mobile-sdk-android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
protected void setupSettings() {
    Settings.getSettings().ua = this.getSettings().getUserAgentString();
    this.getSettings().setJavaScriptEnabled(true);
    this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    this.getSettings().setBuiltInZoomControls(false);
    this.getSettings().setLightTouchEnabled(false);
    this.getSettings().setLoadsImagesAutomatically(true);
    this.getSettings().setSupportZoom(false);
    this.getSettings().setUseWideViewPort(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        this.getSettings().setMediaPlaybackRequiresUserGesture(false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        this.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }
    this.getSettings().setAllowFileAccess(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        this.getSettings().setAllowContentAccess(false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        this.getSettings().setAllowFileAccessFromFileURLs(false);
        this.getSettings().setAllowUniversalAccessFromFileURLs(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager cm = CookieManager.getInstance();
        if (cm != null) {
            cm.setAcceptThirdPartyCookies(this, true);
        } else {
            Clog.d(Clog.baseLogTag, "Failed to set Webview to accept 3rd party cookie");
        }
    }

    setHorizontalScrollbarOverlay(false);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollbarOverlay(false);
    setVerticalScrollBarEnabled(false);

    setBackgroundColor(Color.TRANSPARENT);
    setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
}