本文整理汇总了Java中android.webkit.WebSettings.setJavaScriptEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java WebSettings.setJavaScriptEnabled方法的具体用法?Java WebSettings.setJavaScriptEnabled怎么用?Java WebSettings.setJavaScriptEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.WebSettings
的用法示例。
在下文中一共展示了WebSettings.setJavaScriptEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint({"AddJavascriptInterface", "SetJavaScriptEnabled"})
private void init() {
setClickable(false);
setFocusable(false);
setHorizontalScrollBarEnabled(false);
WebSettings settings = getSettings();
settings.setDefaultFontSize(14);
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
settings.setDisplayZoomControls(false);
settings.setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
addJavascriptInterface(new OnWebViewImageListener() {
@Override
@JavascriptInterface
public void showImagePreview(String bigImageUrl) {
if (bigImageUrl != null && !StringUtils.isEmpty(bigImageUrl)) {
ImageGalleryActivity.show(getContext(), bigImageUrl);
}
}
}, "mWebViewImageListener");
}
}
示例2: writeEncryToken
import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint({"SetJavaScriptEnabled"})
public void writeEncryToken(Context context) {
String str = "tencent&sdk&qazxc***14969%%";
String accessToken = this.mToken.getAccessToken();
String appId = this.mToken.getAppId();
String openId = this.mToken.getOpenId();
String str2 = "qzone3.4";
if (accessToken == null || accessToken.length() <= 0 || appId == null || appId.length() <= 0 || openId == null || openId.length() <= 0) {
str = null;
} else {
str = Util.encrypt(str + accessToken + appId + openId + str2);
}
com.tencent.open.c.b bVar = new com.tencent.open.c.b(context);
WebSettings settings = bVar.getSettings();
settings.setDomStorageEnabled(true);
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
accessToken = "<!DOCTYPE HTML><html lang=\"en-US\"><head><meta charset=\"UTF-8\"><title>localStorage Test</title><script type=\"text/javascript\">document.domain = 'qq.com';localStorage[\"" + this.mToken.getOpenId() + EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR + this.mToken.getAppId() + "\"]=\"" + str + "\";</script></head><body></body></html>";
str = ServerSetting.getInstance().getEnvUrl(context, ServerSetting.DEFAULT_LOCAL_STORAGE_URI);
bVar.loadDataWithBaseURL(str, accessToken, "text/html", "utf-8", str);
}
示例3: onCreate
import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化两个栈的数据结构
backStack = new Stack<URL>();
forwardStack = new Stack<URL>();
//获取两个按钮实例
backButton = (Button)findViewById(R.id.backButton);
forwardButton = (Button) findViewById(R.id.forwardButton);
//获取输入框实例
editor = (EditText) findViewById(R.id.url);
//获取显示区域实例
stage = (WebView) findViewById(R.id.content);
WebSettings settings = stage.getSettings();
settings.setJavaScriptEnabled(true);
stage.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
client = new Client(backStack,editor);
stage.setWebViewClient(client);
//初始化,设置主页为www.smxy.cn
stage.loadUrl("http://www.smxy.cn");
// currentURL = "http://www.smxy.cn";
//editor.setText(currentURL);
}
示例4: initWebView
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initWebView(String url) {
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setGeolocationEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDisplayZoomControls(false);
if (Build.VERSION.SDK_INT >= 21) {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
mWebView.setWebChromeClient(new MyWebChromeClient());
mWebView.loadUrl(url);
}
示例5: onCreate
import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
resultCode = RESULT_OK;
setContentView(R.layout.print_dialog);
dialogWebView = (WebView) findViewById(R.id.webview);
cloudPrintIntent = this.getIntent();
WebSettings settings = dialogWebView.getSettings();
settings.setJavaScriptEnabled(true);
dialogWebView.setWebViewClient(new PrintDialogWebClient());
dialogWebView.addJavascriptInterface(
new PrintDialogJavaScriptInterface(), JS_INTERFACE);
dialogWebView.loadUrl(PRINT_DIALOG_URL);
}
示例6: SourceEditor
import android.webkit.WebSettings; //导入方法依赖的package包/类
/**
* Create source editor using given web view
*
* @param view
*/
@SuppressLint("AddJavascriptInterface")
public SourceEditor(final WebView view) {
WebSettings settings = view.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
try {
int version = Build.VERSION.SDK_INT;
if (version >= 11) {
// 这个方法在API level 11 以上才可以调用,不然会发生异常
settings.setDisplayZoomControls(false);
}
} catch (NumberFormatException e) {
}
settings.setUseWideViewPort(true);
view.addJavascriptInterface(SourceEditor.this, "SourceEditor");
this.view = view;
}
示例7: initWebView
import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled", "AddJavascriptInterface"})
private void initWebView() {
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
mWebView.addJavascriptInterface(new JsInterface(this), "imgClickListener");
mWebView.addJavascriptInterface(new JsInterface(this), "comjs");
mWebView.setWebViewClient(new BaseWebViewClient());
}
示例8: onCreateView
import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view= inflater.inflate(R.layout.fragment_educator, container, false);
web=(WebView)view.findViewById(R.id.web_View);
WebSettings webs =web.getSettings();
webs.setJavaScriptEnabled(true);
web.loadUrl(myUrl);
web.setWebViewClient(new myWebViewClient());
return view;
}
示例9: initWeb
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initWeb() {
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
mWebView.loadUrl("file:///android_asset/speedtest.html");
mWebView.setWebViewClient(new WebViewClient());
}
示例10: destroy
import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
public void destroy() {
setWebViewClient(null);
WebSettings settings = getSettings();
settings.setJavaScriptEnabled(false);
removeAllViewsInLayout();
removeAllViews();
super.destroy();
}
示例11: AccountCreationWebview
import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint("SetJavaScriptEnabled")
public AccountCreationWebview(BasePrefsWizard aParent, String url, OnAccountCreationDoneListener l){
parent = aParent;
creationListener = l;
webCreationPage = url;
settingsContainer = (ViewGroup) parent.findViewById(R.id.settings_container);
validationBar = (ViewGroup) parent.findViewById(R.id.validation_bar);
ViewGroup globalContainer = (ViewGroup) settingsContainer.getParent();
parent.getLayoutInflater().inflate(R.layout.wizard_account_creation_webview, globalContainer);
webView = (WebView) globalContainer.findViewById(R.id.webview);
loadingProgressBar = (ProgressBar) globalContainer.findViewById(R.id.webview_progress);
WebSettings webSettings = webView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
webSettings.setCacheMode(WebSettings.LOAD_NORMAL);
webSettings.setNeedInitialFocus(true);
webView.addJavascriptInterface(new JSInterface(), "CSipSimpleWizard");
// Adds Progress bar Support
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if(progress < 100) {
loadingProgressBar.setVisibility(View.VISIBLE);
loadingProgressBar.setProgress(progress);
}else {
loadingProgressBar.setVisibility(View.GONE);
}
}
});
}
示例12: MarkdownView
import android.webkit.WebSettings; //导入方法依赖的package包/类
@SuppressLint({"AddJavascriptInterface", "SetJavaScriptEnabled"})
public MarkdownView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
if (isInEditMode()) {
return;
}
WebSettings settings = getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
initialize();
}
示例13: initData
import android.webkit.WebSettings; //导入方法依赖的package包/类
private void initData() {
WebSettings settings = logisticsWebView.getSettings();
settings.setJavaScriptEnabled(true);//开启webview支持JS
settings.setDatabaseEnabled(true);
String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
//启用地理定位
settings.setGeolocationEnabled(true);
//设置定位的数据库路径
settings.setGeolocationDatabasePath(dir);
settings.setDomStorageEnabled(true);
settings.setCacheMode(LOAD_NO_CACHE);
}
示例14: WebViewTask
import android.webkit.WebSettings; //导入方法依赖的package包/类
public WebViewTask(Context context) {
webView = new WebView(context);
webView.addJavascriptInterface(new InJavaScriptLocalObj(), "get_source");
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
webView.loadUrl("javascript:window.get_source.getSource('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setBlockNetworkImage(true);
webSettings.setUserAgentString("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36");
}
示例15: onCreate
import android.webkit.WebSettings; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
setContentView(R.layout.activity_web);
name = getIntent().getExtras().getString(Common.WEBVIEW_EXTRA_NAME);
url = getIntent().getExtras().getString(Common.WEBVIEW_EXTRA_URL);
color = getIntent().getExtras().getInt(Common.WEBVIEW_EXTRA_COLOR);
needsLogin = getIntent().getExtras().getBoolean(Common.WEBVIEW_EXTRA_NLOGIN);
//Action bar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setNavigationBarColor(color);
getWindow().setStatusBarColor(color);
}
app = (App) getApplication();
TextView title = (TextView) findViewById(R.id.toolbar_title);
title.setText(name);
progress = (ProgressBar) findViewById(R.id.web_progressBar);
webView = (WebView) findViewById(R.id.webView);
if (savedInstanceState != null) {
progress.setVisibility(View.INVISIBLE);
webView.setVisibility(View.VISIBLE);
webView.restoreState(savedInstanceState);
}
else {
progress.setVisibility(View.VISIBLE);
webView.setWebViewClient(new WebViewClient());
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUserAgentString("IEMobile");
startControllers();
}
}