android.webkit.WebSettings#setMediaPlaybackRequiresUserGesture ( )源码实例Demo

下面列出了android.webkit.WebSettings#setMediaPlaybackRequiresUserGesture ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

SumerianConnector(WebView webView, Session session, GLSurfaceView surfaceView) {
    mWebView = webView;
    mSession = session;
    mSurfaceView = surfaceView;

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setMediaPlaybackRequiresUserGesture(false);
    mWebView.addJavascriptInterface(new BridgeInterface(), "Android");

    this.mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            view.setBackgroundColor(0x00000000);
        }
    });
}
 
/**
 * 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());
}
 
源代码3 项目: traccar-manager-android   文件: MainFragment.java
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    if ((getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    getWebView().setWebViewClient(webViewClient);
    getWebView().setWebChromeClient(webChromeClient);
    getWebView().addJavascriptInterface(new AppInterface(), "appInterface");

    WebSettings webSettings = getWebView().getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setMediaPlaybackRequiresUserGesture(false);

    String url = PreferenceManager.getDefaultSharedPreferences(
            getActivity()).getString(MainActivity.PREFERENCE_URL, null);

    getWebView().loadUrl(url);
}
 
源代码4 项目: AndroidWallet   文件: JSWebView.java
@SuppressWarnings("deprecation")
@SuppressLint({"SetJavaScriptEnabled", "NewApi", "ObsoleteSdkInt"})
public void initializeSettings(WebSettings settings) {
    settings.setJavaScriptEnabled(true);
    addJavascriptInterface(new JavaScriptUtil(), "DappJsBridge");
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        settings.setAppCacheMaxSize(Long.MAX_VALUE);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        settings.setEnableSmoothTransition(true);
    }
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        settings.setMediaPlaybackRequiresUserGesture(true);
    }

    WebView.setWebContentsDebuggingEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setLoadsImagesAutomatically(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setDatabaseEnabled(true);
    settings.setDisplayZoomControls(false);
    settings.setAllowContentAccess(true);
    settings.setAllowFileAccess(false);
    settings.setRenderPriority(WebSettings.RenderPriority.LOW);
    setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    settings.setDefaultTextEncodingName("utf-8");
    settings.setAllowFileAccessFromFileURLs(false);
    settings.setAllowUniversalAccessFromFileURLs(false);
    // 特别注意:5.1以上默认禁止了https和http混用,以下方式是开启
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
    }
}
 
源代码5 项目: HaoReader   文件: AjaxWebView.java
@SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface"})
private static WebView createAjaxWebView(AjaxParams params, Handler handler) {
    WebView webView = new WebView(params.context.getApplicationContext());
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setBlockNetworkImage(true);
    settings .setMediaPlaybackRequiresUserGesture(false);
    settings.setUserAgentString(params.getUserAgent());
    settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    if (params.isSniff()) {
        webView.setWebViewClient(new SnifferWebClient(params, handler));
    } else {
        webView.setWebViewClient(new HtmlWebViewClient(handler));
        webView.addJavascriptInterface(new JavaInjectMethod(handler), "OUTHTML");
    }
    switch (params.getRequestMethod()) {
        case POST:
            webView.postUrl(params.url, params.postData);
            break;
        case GET:
        case DEFAULT:
            webView.loadUrl(params.url, params.headerMap);
            break;
    }
    return webView;
}
 
源代码6 项目: mv-android-client   文件: WebPlayerView.java
private void init(Context context) {
    mPlayer = new WebPlayer(this);

    setBackgroundColor(Color.BLACK);

    enableJavascript();

    WebSettings webSettings = getSettings();
    webSettings.setAllowContentAccess(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(context.getDir("database", Context.MODE_PRIVATE).getPath());
    webSettings.setDomStorageEnabled(true);
    webSettings.setLoadsImagesAutomatically(true);
    webSettings.setSupportMultipleWindows(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setAllowUniversalAccessFromFileURLs(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            webSettings.setMediaPlaybackRequiresUserGesture(false);
        }
    }

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

    setWebChromeClient(new ChromeClient());
    setWebViewClient(new ViewClient());
}
 
源代码7 项目: OsmGo   文件: Bridge.java
/**
 * Initialize the WebView, setting required flags
 */
private void initWebView() {
  WebSettings settings = webView.getSettings();
  settings.setJavaScriptEnabled(true);
  settings.setDomStorageEnabled(true);
  settings.setGeolocationEnabled(true);
  settings.setDatabaseEnabled(true);
  settings.setAppCacheEnabled(true);
  settings.setMediaPlaybackRequiresUserGesture(false);
  settings.setJavaScriptCanOpenWindowsAutomatically(true);
  if (Config.getBoolean("android.allowMixedContent", false)) {
    settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
  }
  String backgroundColor = Config.getString("android.backgroundColor" , Config.getString("backgroundColor", null));
  try {
    if (backgroundColor != null) {
      webView.setBackgroundColor(Color.parseColor(backgroundColor));
    }
  } catch (IllegalArgumentException ex) {
    Log.d(LogUtils.getCoreTag(), "WebView background color not applied");
  }
  boolean defaultDebuggable = false;
  if (isDevMode()) {
    defaultDebuggable = true;
  }

  WebView.setWebContentsDebuggingEnabled(Config.getBoolean("android.webContentsDebuggingEnabled", defaultDebuggable));
}
 
protected void initWebView(WebView view) {
    webView = view;
    setProgressBarVisibility(true);

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

    WebSettings settings = view.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setUserAgentString(settings.getUserAgentString() + " Web-Atoms-Mobile-WebView");
    settings.setDatabaseEnabled(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    final File dir = this.getExternalCacheDir();
    settings.setAppCacheMaxSize(1024*1024*20);
    settings.setAppCachePath(dir.getAbsolutePath());
    settings.setAllowFileAccess(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    view.setDownloadListener(getDownloadListener());

    CookieManager cookies = CookieManager.getInstance();
    cookies.setAcceptCookie(true);

    setWebViewClient(view);
    setWebChromeClient(view);
}
 
源代码9 项目: chappiecast   文件: MainActivity.java
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    // Set by <content src="index.html" /> in config.xml
    loadUrl(launchUrl);
    WebSettings ws = ((SystemWebView)super.appView.getView()).getSettings();
    ws.setMediaPlaybackRequiresUserGesture(false);
}
 
源代码10 项目: browser   文件: LightningView.java
@SuppressWarnings("deprecation")
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
public void initializeSettings(WebSettings settings, Context context) {
	//setPageCacheCapacity2(settings);
	if (API < 18) {
		settings.setAppCacheMaxSize(Long.MAX_VALUE);
	}
	if (API < 17) {
		settings.setEnableSmoothTransition(true);
	}
	if (API > 16) {
		settings.setMediaPlaybackRequiresUserGesture(true);
	}
	if (API >= Build.VERSION_CODES.LOLLIPOP && !mBrowserController.isIncognito()) {
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
	} else if (API >= Build.VERSION_CODES.LOLLIPOP) {
		// We're in Incognito mode, reject
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
	}
	settings.setDomStorageEnabled(true);
	settings.setAppCacheEnabled(true);
	settings.setCacheMode(WebSettings.LOAD_DEFAULT);
	settings.setDatabaseEnabled(true);
	settings.setSupportZoom(true);
	settings.setBuiltInZoomControls(true);
	settings.setDisplayZoomControls(false);
	settings.setAllowContentAccess(true);
	settings.setAllowFileAccess(true);
	settings.setDefaultTextEncodingName("utf-8");
	if (API > 16) {
		settings.setAllowFileAccessFromFileURLs(false);
		settings.setAllowUniversalAccessFromFileURLs(false);
	}

	settings.setAppCachePath(context.getDir("appcache", 0).getPath());
	settings.setGeolocationDatabasePath(context.getDir("geolocation", 0).getPath());
	if (API < Build.VERSION_CODES.KITKAT) {
		settings.setDatabasePath(context.getDir("databases", 0).getPath());
	}


}
 
源代码11 项目: habpanelviewer   文件: ClientWebView.java
void updateFromPreferences(SharedPreferences prefs) {
    String theme = prefs.getString(Constants.PREF_THEME, "dark");
    mDarkTheme = "dark".equals(theme);
    mImmersive = prefs.getBoolean(Constants.PREF_IMMERSIVE, false);
    mTrackBrowserConnection = prefs.getBoolean(Constants.PREF_TRACK_BROWSER_CONNECTION, false);
    mLogBrowserMsg = prefs.getBoolean(Constants.PREF_LOG_BROWSER_MESSAGES, false);
    mAllowWebRTC = prefs.getBoolean(Constants.PREF_ALLOW_WEBRTC, false);

    boolean isDesktop = prefs.getBoolean(Constants.PREF_DESKTOP_MODE, false);
    boolean isJavascript = prefs.getBoolean(Constants.PREF_JAVASCRIPT, false);
    boolean isAutoplay = prefs.getBoolean(Constants.PREF_AUTOPLAY_VIDEO, false);
    boolean cacheDeactivated = prefs.getBoolean(Constants.PREF_DISABLE_CACHE, false);

    mDraggingPrevented = prefs.getBoolean(Constants.PREF_PREVENT_DRAGGING, false);

    WebSettings webSettings = getSettings();
    webSettings.setUseWideViewPort(isDesktop);
    webSettings.setLoadWithOverviewMode(isDesktop);
    webSettings.setJavaScriptEnabled(isJavascript);
    webSettings.setCacheMode(cacheDeactivated ? WebSettings.LOAD_NO_CACHE : WebSettings.LOAD_DEFAULT);
    webSettings.setMediaPlaybackRequiresUserGesture(!isAutoplay);

    boolean loadStartUrl = false;
    boolean reloadUrl = false;
    if (mStartPage == null || !mStartPage.equalsIgnoreCase(prefs.getString(Constants.PREF_START_URL, ""))) {
        mStartPage = prefs.getString(Constants.PREF_START_URL, "");
        loadStartUrl = true;
    }
    loadStartUrl = loadStartUrl || isShowingErrorPage();

    if (mServerURL == null || !mServerURL.equalsIgnoreCase(prefs.getString(Constants.PREF_SERVER_URL, "!$%"))) {
        mServerURL = prefs.getString(Constants.PREF_SERVER_URL, "");
        loadStartUrl = loadStartUrl || mStartPage == null || mStartPage.isEmpty();
    }
    if (mAllowMixedContent != prefs.getBoolean(Constants.PREF_ALLOW_MIXED_CONTENT, false)) {
        mAllowMixedContent = !mAllowMixedContent;
        reloadUrl = true;
    }

    if (mHwAccelerated != prefs.getBoolean(Constants.PREF_HW_ACCELERATED, false)) {
        mHwAccelerated = !mHwAccelerated;

        if (mHwAccelerated) {
            setLayerType(LAYER_TYPE_HARDWARE, null);
        } else {
            setLayerType(LAYER_TYPE_SOFTWARE, null);
        }
    }


    webSettings.setMixedContentMode(mAllowMixedContent ? WebSettings.MIXED_CONTENT_ALWAYS_ALLOW : WebSettings.MIXED_CONTENT_NEVER_ALLOW);

    if (mNetworkTracker.isConnected()) {
        if (loadStartUrl) {
            loadStartUrl();
        } else if (reloadUrl) {
            reload();
        }
    } else {
        showHtml(getContext().getString(R.string.waitingNetwork),
                getContext().getString(R.string.notConnectedReloadPendingHTML));
    }
}
 
源代码12 项目: keemob   文件: SystemWebViewEngine.java
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
源代码13 项目: keemob   文件: SystemWebViewEngine.java
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
源代码14 项目: unity-ads-android   文件: WebView.java
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");
}
 
源代码15 项目: SimplicityBrowser   文件: NestedWebview.java
@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");
    }

}
 
源代码16 项目: L.TileLayer.Cordova   文件: CordovaWebView.java
static void setMediaPlaybackRequiresUserGesture(WebSettings settings, boolean value) {
    settings.setMediaPlaybackRequiresUserGesture(value);
}
 
源代码17 项目: bluemix-parking-meter   文件: CordovaWebView.java
static void setMediaPlaybackRequiresUserGesture(WebSettings settings, boolean value) {
    settings.setMediaPlaybackRequiresUserGesture(value);
}
 
源代码18 项目: pychat   文件: SystemWebViewEngine.java
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
源代码19 项目: lona   文件: SystemWebViewEngine.java
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
源代码20 项目: countly-sdk-cordova   文件: SystemWebViewEngine.java
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}