當前位置: 首頁>>代碼示例>>Java>>正文


Java WebSettings.setJavaScriptEnabled方法代碼示例

本文整理匯總了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");
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:27,代碼來源:OWebView.java

示例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);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:22,代碼來源:SocialApiIml.java

示例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);


}
 
開發者ID:mgsky1,項目名稱:WebStackDemo,代碼行數:27,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:woxingxiao,項目名稱:GracefulMovies,代碼行數:22,代碼來源:WebActivity.java

示例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);
}
 
開發者ID:ArtifexSoftware,項目名稱:mupdf-android-viewer-old,代碼行數:19,代碼來源:PrintDialogActivity.java

示例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;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:24,代碼來源:SourceEditor.java

示例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());
}
 
開發者ID:shenhuanet,項目名稱:ZhidaoDaily-android,代碼行數:10,代碼來源:DetailActivity.java

示例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;
}
 
開發者ID:IOSD,項目名稱:YFHR_Android_App,代碼行數:13,代碼來源:educator.java

示例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());
}
 
開發者ID:JunGeges,項目名稱:AliZhiBoHao,代碼行數:12,代碼來源:SpeedTestActivity.java

示例10: destroy

import android.webkit.WebSettings; //導入方法依賴的package包/類
@Override
public void destroy() {
    setWebViewClient(null);

    WebSettings settings = getSettings();
    settings.setJavaScriptEnabled(false);

    removeAllViewsInLayout();

    removeAllViews();
    super.destroy();
}
 
開發者ID:bigjelly,項目名稱:ShaddockVideoPlayer,代碼行數:13,代碼來源:NWebView.java

示例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);
            }
        }
    });
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:38,代碼來源:AccountCreationWebview.java

示例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();
}
 
開發者ID:GcsSloop,項目名稱:diycode,代碼行數:13,代碼來源:MarkdownView.java

示例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);
}
 
開發者ID:MedicationReminder,項目名稱:MedicationReminder,代碼行數:15,代碼來源:LogisticsWebActivity.java

示例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");
}
 
開發者ID:lanyuanxiaoyao,項目名稱:PicKing,代碼行數:16,代碼來源:WebViewTask.java

示例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();
    }

}
 
開發者ID:Onelio,項目名稱:ConnectU,代碼行數:41,代碼來源:WebActivity.java


注:本文中的android.webkit.WebSettings.setJavaScriptEnabled方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。