Java Code Examples for android.webkit.WebSettings#setPluginState()

The following examples show how to use android.webkit.WebSettings#setPluginState() . 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: BaseWebView.java    From RichWebList with Apache License 2.0 6 votes vote down vote up
private void initWebViewSettings() {
	WebSettings webSetting = this.getSettings();
	webSetting.setJavaScriptEnabled(true);
	webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
	webSetting.setAllowFileAccess(true);
	webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
	webSetting.setSupportZoom(true);
	webSetting.setBuiltInZoomControls(true);
	webSetting.setUseWideViewPort(true);
	webSetting.setSupportMultipleWindows(true);
	// webSetting.setLoadWithOverviewMode(true);
	webSetting.setAppCacheEnabled(true);
	// webSetting.setDatabaseEnabled(true);
	webSetting.setDomStorageEnabled(true);
	webSetting.setGeolocationEnabled(true);
	webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
	// webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
	webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
	// webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
	webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

	// this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
	// settings 的设计
}
 
Example 2
Source File: YouTubePlayerWebView.java    From android-inline-youtube-view with Apache License 2.0 6 votes vote down vote up
/**
 * Initialises YoutubeWebView with given videoId and youtubeListener
 */
@SuppressLint("SetJavaScriptEnabled")
private void initWebView(String webViewUrl) {
    WebSettings set = this.getSettings();
    set.setJavaScriptEnabled(true);
    set.setUseWideViewPort(true);
    set.setLoadWithOverviewMode(true);
    set.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    set.setCacheMode(WebSettings.LOAD_DEFAULT);
    set.setPluginState(WebSettings.PluginState.ON_DEMAND);
    set.setAllowContentAccess(true);
    set.setAllowFileAccess(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        set.setMediaPlaybackRequiresUserGesture(false);
    }
    this.setLayerType(View.LAYER_TYPE_NONE, null);
    this.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    this.loadUrl(webViewUrl);

    if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setWebContentsDebuggingEnabled(true);
    }

    this.setWebViewClient(initWebViewClient());
}
 
Example 3
Source File: FindGankDetailAty.java    From myapplication with Apache License 2.0 6 votes vote down vote up
private void fillGankDatas() {
    Intent intent = getIntent();
    mGankResultBean = (SearchResultsBean) intent.getSerializableExtra("gankItemInfos");
    mGankDescStr = mGankResultBean.getDesc();
    mMarqueeTextView.setText(mGankDescStr);

    mGankUrlStr = mGankResultBean.getUrl();
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    webSettings.setSupportZoom(false);
    webSettings.setPluginState(WebSettings.PluginState.ON);

    mWebView.setWebChromeClient(new FindGankDetailAty.MyWebChromeClient());
    mWebView.setWebViewClient(new FindGankDetailAty.MyWebViewClient());
    mWebView.loadUrl(mGankUrlStr);
}
 
Example 4
Source File: DetailFragment.java    From ListItemFold with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_blank, container, false);

    mWebview = (WebView) view.findViewById(R.id.h5_web);
    WebSettings webSettings = mWebview.getSettings();
    webSettings.setSupportZoom(false);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setJavaScriptEnabled(true);
    mWebview.setWebChromeClient(new WebChromeClient());
    mWebview.setWebViewClient(new WebViewClient());
    mWebview.loadUrl(mUrl);
    DetailAnimViewGroup wrapper = new DetailAnimViewGroup(inflater.getContext(), view, 0);
    wrapper.setReversed(false);
    return wrapper;
}
 
Example 5
Source File: WebSettingsCompatFroyo.java    From Android_Skin_2.0 with Apache License 2.0 6 votes vote down vote up
public static void setPluginState(WebSettings settings, PluginStateCompat state) {
	switch (state) {
	case ON: {
		settings.setPluginState(PluginState.ON);
		break;
	}
	case ON_DEMAND: {
		settings.setPluginState(PluginState.ON_DEMAND);
		break;
	}
	case OFF: {
		settings.setPluginState(PluginState.OFF);
		break;
	}
	default: {
		break;
	}
	}
}
 
Example 6
Source File: PluginWebViewActivity.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
private void setUpWebViewSetting() {
	WebSettings webSettings = web.getSettings();

	webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);// 根据cache-control决定是否从网络上取数据
	webSettings.setSupportZoom(true);
	webSettings.setBuiltInZoomControls(true);// 显示放大缩小
	webSettings.setJavaScriptEnabled(true);
	// webSettings.setPluginsEnabled(true);
	webSettings.setPluginState(PluginState.ON);
	webSettings.setUserAgentString(webSettings.getUserAgentString());
	webSettings.setDomStorageEnabled(true);
	webSettings.setAppCacheEnabled(true);
	webSettings.setAppCachePath(getCacheDir().getPath());
	webSettings.setUseWideViewPort(true);// 影响默认满屏和双击缩放
	webSettings.setLoadWithOverviewMode(true);// 影响默认满屏和手势缩放

}
 
Example 7
Source File: WebActivity.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
private void setUpWebViewSetting() {
	WebSettings webSettings = web.getSettings();

	webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);// 根据cache-control决定是否从网络上取数据
	webSettings.setSupportZoom(true);
	webSettings.setBuiltInZoomControls(true);// 显示放大缩小
	webSettings.setJavaScriptEnabled(true);
	// webSettings.setPluginsEnabled(true);
	webSettings.setPluginState(WebSettings.PluginState.ON);
	webSettings.setUserAgentString(webSettings.getUserAgentString());
	webSettings.setDomStorageEnabled(true);
	webSettings.setAppCacheEnabled(true);
	webSettings.setAppCachePath(getCacheDir().getPath());
	webSettings.setUseWideViewPort(true);// 影响默认满屏和双击缩放
	webSettings.setLoadWithOverviewMode(true);// 影响默认满屏和手势缩放

}
 
Example 8
Source File: TestCaseListActivity.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
private void setUpWebViewSetting(WebView web) {
    WebSettings webSettings = web.getSettings();

    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);// 根据cache-control决定是否从网络上取数据
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);// 显示放大缩小
    webSettings.setJavaScriptEnabled(true);
    // webSettings.setPluginsEnabled(true);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setUserAgentString(webSettings.getUserAgentString());
    webSettings.setDomStorageEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setAppCachePath(getCacheDir().getPath());
    webSettings.setUseWideViewPort(true);// 影响默认满屏和双击缩放
    webSettings.setLoadWithOverviewMode(true);// 影响默认满屏和手势缩放

}
 
Example 9
Source File: BaseWebView.java    From dcs-sdk-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void init(Context context) {
    this.setVerticalScrollBarEnabled(false);
    this.setHorizontalScrollBarEnabled(false);
    if (Build.VERSION.SDK_INT < 19) {
        removeJavascriptInterface("searchBoxJavaBridge_");
    }

    WebSettings localWebSettings = this.getSettings();
    try {
        // 禁用file协议,http://www.tuicool.com/articles/Q36ZfuF, 防止Android WebView File域攻击
        localWebSettings.setAllowFileAccess(false);
        localWebSettings.setSupportZoom(false);
        localWebSettings.setBuiltInZoomControls(false);
        localWebSettings.setUseWideViewPort(true);
        localWebSettings.setDomStorageEnabled(true);
        localWebSettings.setLoadWithOverviewMode(true);
        localWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        localWebSettings.setPluginState(PluginState.ON);
        // 启用数据库
        localWebSettings.setDatabaseEnabled(true);
        // 设置定位的数据库路径
        String dir = context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
        localWebSettings.setGeolocationDatabasePath(dir);
        localWebSettings.setGeolocationEnabled(true);
        localWebSettings.setJavaScriptEnabled(true);
        localWebSettings.setSavePassword(false);
        String agent = localWebSettings.getUserAgentString();

        localWebSettings.setUserAgentString(agent);
        // setCookie(context, ".baidu.com", bdussCookie);

    } catch (Exception e1) {
        e1.printStackTrace();
    }
    this.setWebViewClient(new BridgeWebViewClient());
}
 
Example 10
Source File: BaseWebActivity.java    From Aurora with Apache License 2.0 5 votes vote down vote up
protected void configWebView() {
    mWebView = new WebView(getApplicationContext());
    mWebViewContainer.addView(mWebView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDefaultTextEncodingName("UTF-8");
    settings.setSupportZoom(false);
    settings.setPluginState(WebSettings.PluginState.ON);
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
}
 
Example 11
Source File: BaseWebActivity.java    From Dota2Helper with Apache License 2.0 5 votes vote down vote up
protected void configWebView() {
    mWebView = new WebView(getApplicationContext());
    mWebViewContainer.addView(mWebView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDefaultTextEncodingName("UTF-8");
    settings.setSupportZoom(false);
    settings.setPluginState(WebSettings.PluginState.ON);
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
}
 
Example 12
Source File: FindVideoDetailAty.java    From myapplication with Apache License 2.0 5 votes vote down vote up
private void fillVideoDatas() throws ParseException {
        Intent intent = getIntent();
        mVideoResultsBean = (VideoResultsBean) intent.getSerializableExtra("videoItemInfos");


        mVideoItemUrlStr = mVideoResultsBean.getUrl();
        Log.i("TAG", "mVideoItemUrlStr: " + mVideoItemUrlStr);

//        mVideoItemDescStr = "『" + mVideoResultsBean.getDesc() + "』";
//        mVideoItemPublishAtStr = "PublishedAt: " +
//                DateUtil.utc2LocalTime(mVideoResultsBean.getPublishedAt());
//        mVideoItemCreateAtStr = "CreatedAt: " +
//                DateUtil.utc2LocalTime(mVideoResultsBean.getCreatedAt());
//        mVideoItemSourceStr = "Source from: " + mVideoResultsBean.getSource();
//        mVideoItemWhoStr = "Shared by: " + mVideoResultsBean.getWho();

//        mVideoDescTv.setText(mVideoItemDescStr);
//        mVideoPublishedAtTv.setText(mVideoItemPublishAtStr);
//        mVideoCreateAtTv.setText(mVideoItemCreateAtStr);
//        mVideoSourceTv.setText(mVideoItemSourceStr);
//        mVideoWhoTv.setText(mVideoItemWhoStr);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setAppCacheEnabled(true);
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setSupportZoom(false);
        webSettings.setPluginState(WebSettings.PluginState.ON);

        mWebView.setBackgroundColor(255); // 设置背景色
        mWebView.getBackground().setAlpha(249); // 设置填充透明度 范围:0-255
        mWebView.setWebChromeClient(new MyWebChromeClient());
        mWebView.setWebViewClient(new MyWebViewClient());
        mWebView.loadUrl(mVideoItemUrlStr);

    }
 
Example 13
Source File: Browser.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化浏览器设置信息
 */
private void initWebView() {
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true); // 启用支持javascript
    webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);// 优先使用缓存
    webSettings.setAllowFileAccess(true);// 可以访问文件
    webSettings.setBuiltInZoomControls(true);// 支持缩放
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        webSettings.setPluginState(PluginState.ON);
        webSettings.setDisplayZoomControls(false);// 支持缩放
    }
    mWebView.setWebViewClient(new MyWebViewClient());
    mWebView.setWebChromeClient(new MyWebChromeClient());
}
 
Example 14
Source File: MyWebView.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
private void init(Context context) {
    if (!(context instanceof Activity)) {
        throw new RuntimeException("only support Activity context");
    } else {
        this.mContainerActivity = (Activity) context;
        WebSettings webSettings = this.getSettings();
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setAllowFileAccess(false);
        webSettings.setLoadsImagesAutomatically(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setDefaultTextEncodingName("UTF-8");
        webSettings.setDomStorageEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(false);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
            webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setWebContentsDebuggingEnabled(true);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webSettings.setMixedContentMode(0);
        }

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            this.removeJavascriptInterface("searchBoxJavaBridge_");
            this.removeJavascriptInterface("accessibilityTraversal");
            this.removeJavascriptInterface("accessibility");
        }
        mMyWebViewClient = new MyWebViewClient();
        this.setWebViewClient(mMyWebViewClient);
        this.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress < 100) {
                    showLoadProgress(newProgress);
                } else {
                    hideLoadProgress();
                }
            }
        });

        addProgressView();
    }
}
 
Example 15
Source File: WebPlayerView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
public WebPlayerView(Context context, String viewId, JSONObject webSettings, JSONObject webPlayerSettings) {
	super(context);

	this.viewId = viewId;

	WebSettings settings = getSettings();

	if(Build.VERSION.SDK_INT >= 16) {
		settings.setAllowFileAccessFromFileURLs(false);
		settings.setAllowUniversalAccessFromFileURLs(false);
	}
	if (Build.VERSION.SDK_INT >= 19) {
		try {
			_evaluateJavascript = WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class);
		} catch(NoSuchMethodException e) {
			DeviceLog.exception("Method evaluateJavascript not found", e);
			_evaluateJavascript = null;
		}
	}

	settings.setAppCacheEnabled(false);
	settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
	settings.setDatabaseEnabled(false);

	settings.setDomStorageEnabled(false);
	settings.setGeolocationEnabled(false);
	settings.setJavaScriptEnabled(true);
	settings.setLoadsImagesAutomatically(true);

	settings.setPluginState(WebSettings.PluginState.OFF);
	settings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
	settings.setSaveFormData(false);
	settings.setSavePassword(false);

	setHorizontalScrollBarEnabled(false);
	setVerticalScrollBarEnabled(false);
	setInitialScale(0);
	setBackgroundColor(Color.TRANSPARENT);
	ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT));
	setBackgroundResource(0);

	setSettings(webSettings, webPlayerSettings);

	setWebViewClient(new WebPlayerClient());
	setWebChromeClient(new WebPlayerChromeClient());
	setDownloadListener(new WebPlayerDownloadListener());

	addJavascriptInterface(new WebPlayerBridgeInterface(viewId), "webplayerbridge");

	WebPlayerViewCache.getInstance().addWebPlayer(viewId, this);

	this.subscribeOnLayoutChange();
}
 
Example 16
Source File: WebView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
public WebView(Context context) {
	super(context);
	WebSettings settings = getSettings();

	if(Build.VERSION.SDK_INT >= 16) {
		settings.setAllowFileAccessFromFileURLs(true);
		settings.setAllowUniversalAccessFromFileURLs(true);
	}

	if (Build.VERSION.SDK_INT >= 19) {
		try {
			_evaluateJavascript = android.webkit.WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class);
		} catch(NoSuchMethodException e) {
			DeviceLog.exception("Method evaluateJavascript not found", e);
			_evaluateJavascript = null;
		}
	}

	settings.setAppCacheEnabled(false);
	settings.setBlockNetworkImage(false);
	settings.setBlockNetworkLoads(false);
	settings.setBuiltInZoomControls(false);
	settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
	settings.setDatabaseEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setDisplayZoomControls(false);
	}

	settings.setDomStorageEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setEnableSmoothTransition(false);
	}

	settings.setGeolocationEnabled(false);
	settings.setJavaScriptCanOpenWindowsAutomatically(false);
	settings.setJavaScriptEnabled(true);
	settings.setLightTouchEnabled(false);
	settings.setLoadWithOverviewMode(false);
	settings.setLoadsImagesAutomatically(true);

	if(Build.VERSION.SDK_INT >= 17) {
		settings.setMediaPlaybackRequiresUserGesture(false);
	}

	if(Build.VERSION.SDK_INT >= 21) {
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
	}

	settings.setNeedInitialFocus(true);
	settings.setPluginState(WebSettings.PluginState.OFF);
	settings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
	settings.setSaveFormData(false);
	settings.setSavePassword(false);
	settings.setSupportMultipleWindows(false);
	settings.setSupportZoom(false);
	settings.setUseWideViewPort(true);

	setHorizontalScrollBarEnabled(false);
	setVerticalScrollBarEnabled(false);
	setInitialScale(0);
	setBackgroundColor(Color.TRANSPARENT);
	ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT));
	setBackgroundResource(0);

	addJavascriptInterface(new WebViewBridgeInterface(), "webviewbridge");
}