android.webkit.WebView#setWebContentsDebuggingEnabled ( )源码实例Demo

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

源代码1 项目: 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);
}
 
源代码2 项目: JsBridge   文件: CustomWebViewActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle("Custom WebView");
    jsBridge = JsBridge.loadModule();
    WebView.setWebContentsDebuggingEnabled(true);
    customWebView = new CustomWebView(this);
    setContentView(customWebView);
    customWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            jsBridge.injectJs(customWebView);
        }
    });
    customWebView.setPromptResult(new PromptResultCallback() {
        @Override
        public void onResult(String args, PromptResultImpl promptResult) {
            jsBridge.callJsPrompt(args, promptResult);
        }
    });
    customWebView.loadUrl("file:///android_asset/sample.html");
}
 
源代码3 项目: something.apk   文件: ThreadViewFragment.java
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface", "NewApi"})
private void initWebview() {
    threadView.getSettings().setJavaScriptEnabled(true);
    threadView.setWebChromeClient(chromeClient);
    threadView.setWebViewClient(webClient);
    threadView.addJavascriptInterface(new SomeJavascriptInterface(), "listener");

    if (Constants.DEBUG && SomeUtils.isKitKat()) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    if (SomeUtils.isLollipop()) {
        threadView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    if (SomeUtils.isJellybean()) {
        threadView.getSettings().setAllowUniversalAccessFromFileURLs(true);
        threadView.getSettings().setAllowFileAccessFromFileURLs(true);
        threadView.getSettings().setAllowFileAccess(true);
        threadView.getSettings().setAllowContentAccess(true);
    }

    threadView.setBackgroundColor(SomeTheme.getThemeColor(getActivity(), R.attr.webviewBackgroundColor, Color.BLACK));

    registerForContextMenu(threadView);
}
 
源代码4 项目: alpha-wallet-android   文件: Web3View.java
@SuppressLint("SetJavaScriptEnabled")
public void init() {
    jsInjectorClient = new JsInjectorClient(getContext());
    webViewClient = new Web3ViewClient(jsInjectorClient, new UrlHandlerManager());
    WebSettings webSettings = getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setUserAgentString(webSettings.getUserAgentString()
                                           + "AlphaWallet(Platform=Android&AppVersion=" + BuildConfig.VERSION_NAME + ")");
    WebView.setWebContentsDebuggingEnabled(true); //so devs can debug their scripts/pages
    addJavascriptInterface(new SignCallbackJSInterface(
            this,
            innerOnSignTransactionListener,
            innerOnSignMessageListener,
            innerOnSignPersonalMessageListener,
            innerOnSignTypedMessageListener), "alpha");
}
 
源代码5 项目: BigDataPlatform   文件: SystemWebViewEngine.java
@TargetApi(Build.VERSION_CODES.KITKAT)
private void enableRemoteDebugging() {
    try {
        WebView.setWebContentsDebuggingEnabled(true);
    } catch (IllegalArgumentException e) {
        LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    }
}
 
源代码6 项目: 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);
    }
}
 
源代码7 项目: tysq-android   文件: BitWebViewFragment.java
@Override
protected void initView(View view) {
    initWebView(mWebView);
    initWebViewSetting(mWebView.getSettings());

    mWebView.loadUrl(this.mUrl, BitWebViewManager.getInstance().getWebViewConfig().getHeader());
    WebView.setWebContentsDebuggingEnabled(true);
}
 
源代码8 项目: lona   文件: SystemWebViewEngine.java
private void enableRemoteDebugging() {
    try {
        WebView.setWebContentsDebuggingEnabled(true);
    } catch (IllegalArgumentException e) {
        LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    }
}
 
源代码9 项目: app-icon   文件: SystemWebViewEngine.java
@TargetApi(Build.VERSION_CODES.KITKAT)
private void enableRemoteDebugging() {
    try {
        WebView.setWebContentsDebuggingEnabled(true);
    } catch (IllegalArgumentException e) {
        LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    }
}
 
@TargetApi(Build.VERSION_CODES.KITKAT)
private void enableRemoteDebugging() {
    try {
        WebView.setWebContentsDebuggingEnabled(true);
    } catch (IllegalArgumentException e) {
        LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    }
}
 
源代码11 项目: JsWebView   文件: BridgeWebView.java
private void init() {
    this.setVerticalScrollBarEnabled(false);
    this.setHorizontalScrollBarEnabled(false);
    this.getSettings().setJavaScriptEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    this.setWebViewClient(generateBridgeWebViewClient());
}
 
源代码12 项目: quill   文件: WebViewFragment.java
@SuppressLint("SetJavaScriptEnabled")
@NonNull @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    @LayoutRes int layoutId = getArguments().getInt(KEY_LAYOUT_ID);
    View view = inflater.inflate(layoutId, container, false);
    // not using ButterKnife to ensure WebView is private
    // but still need to call bindView() to maintain base class contract
    bindView(view);
    mWebView = (WebView) view.findViewById(R.id.web_view);
    mUrl = getArguments().getString(BundleKeys.URL);
    if (TextUtils.isEmpty(mUrl)) {
        throw new IllegalArgumentException("Empty URL passed to WebViewFragment!");
    }
    Crashlytics.log(Log.DEBUG, TAG, "Loading URL: " + mUrl);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);

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

    mWebView.setWebViewClient(new DefaultWebViewClient());
    mWebView.loadUrl(mUrl);

    return view;
}
 
源代码13 项目: quickhybrid-android   文件: QuickWebView.java
/**
 * 初始化设置
 */
public void settingWebView() {
    WebSettings settings = getSettings();
    String ua = settings.getUserAgentString();
    // 设置浏览器UA,JS端通过UA判断是否属于Quick环境
    settings.setUserAgentString(ua + " QuickHybridJs/" + BuildConfig.VERSION_NAME);
    // 设置支持JS
    settings.setJavaScriptEnabled(true);
    // 设置是否支持meta标签来控制缩放
    settings.setUseWideViewPort(true);
    // 缩放至屏幕的大小
    settings.setLoadWithOverviewMode(true);
    // 设置内置的缩放控件(若SupportZoom为false,该设置项无效)
    settings.setBuiltInZoomControls(true);
    // 设置缓存模式
    // LOAD_DEFAULT 根据HTTP协议header中设置的cache-control属性来执行加载策略
    // LOAD_CACHE_ELSE_NETWORK 只要本地有无论是否过期都从本地获取
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setDomStorageEnabled(true);
    // 设置AppCache 需要H5页面配置manifest文件(官方已不推介使用)
    String appCachePath = getContext().getCacheDir().getAbsolutePath();
    settings.setAppCachePath(appCachePath);
    settings.setAppCacheEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // 强制开启android webview debug模式使用Chrome inspect(https://developers.google.com/web/tools/chrome-devtools/remote-debugging/)
        WebView.setWebContentsDebuggingEnabled(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
    }
}
 
源代码14 项目: chromium-webview-samples   文件: MainActivity.java
/**
 * Convenience method to set some generic defaults for a
 * given WebView
 *
 * @param webView
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
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());
}
 
源代码15 项目: IoTgo_Android_App   文件: CordovaWebView.java
@TargetApi(Build.VERSION_CODES.KITKAT)
private void enableRemoteDebugging() {
    try {
        WebView.setWebContentsDebuggingEnabled(true);
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    }
}
 
源代码16 项目: keemob   文件: SystemWebViewEngine.java
private void enableRemoteDebugging() {
    try {
        WebView.setWebContentsDebuggingEnabled(true);
    } catch (IllegalArgumentException e) {
        LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    }
}
 
源代码17 项目: JumpGo   文件: BrowserApp.java
@Override
public void onCreate() {
    super.onCreate();
    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectAll()
            .penaltyLog()
            .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
            .detectAll()
            .penaltyLog()
            .build());
    }

    final Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, @NonNull Throwable ex) {

            if (BuildConfig.DEBUG) {
                FileUtils.writeCrashToStorage(ex);
            }

            if (defaultHandler != null) {
                defaultHandler.uncaughtException(thread, ex);
            } else {
                System.exit(2);
            }
        }
    });

    sAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
    sAppComponent.inject(this);

    Schedulers.worker().execute(new Runnable() {
        @Override
        public void run() {
            List<HistoryItem> oldBookmarks = LegacyBookmarkManager.destructiveGetBookmarks(BrowserApp.this);

            if (!oldBookmarks.isEmpty()) {
                // If there are old bookmarks, import them
                mBookmarkModel.addBookmarkList(oldBookmarks).subscribeOn(Schedulers.io()).subscribe();
            } else if (mBookmarkModel.count() == 0) {
                // If the database is empty, fill it from the assets list
                List<HistoryItem> assetsBookmarks = BookmarkExporter.importBookmarksFromAssets(BrowserApp.this);
                mBookmarkModel.addBookmarkList(assetsBookmarks).subscribeOn(Schedulers.io()).subscribe();
            }
        }
    });

    if (mPreferenceManager.getUseLeakCanary() && !isRelease()) {
        LeakCanary.install(this);
    }
    if (!isRelease() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    registerActivityLifecycleCallbacks(new MemoryLeakUtils.LifecycleAdapter() {
        @Override
        public void onActivityDestroyed(Activity activity) {
            Log.d(TAG, "Cleaning up after the Android framework");
            MemoryLeakUtils.clearNextServedView(activity, BrowserApp.this);
        }
    });
}
 
源代码18 项目: GotoBrowser   文件: WebViewManager.java
public static void setWebViewDebugging(boolean enabled) {
    WebView.setWebContentsDebuggingEnabled(enabled);
}
 
源代码19 项目: Hentoid   文件: BaseWebActivity.java
@SuppressLint("SetJavaScriptEnabled")
private void initWebView() {

    try {
        webView = new NestedScrollWebView(this);
    } catch (Resources.NotFoundException e) {
        // Some older devices can crash when instantiating a WebView, due to a Resources$NotFoundException
        // Creating with the application Context fixes this, but is not generally recommended for view creation
        webView = new NestedScrollWebView(Helper.getFixedContext(this));
    }

    webView.setHapticFeedbackEnabled(false);
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress == 100) {
                swipeLayout.post(() -> swipeLayout.setRefreshing(false));
            } else {
                swipeLayout.post(() -> swipeLayout.setRefreshing(true));
            }
        }
    });

    boolean bWebViewOverview = Preferences.getWebViewOverview();
    int webViewInitialZoom = Preferences.getWebViewInitialZoom();

    if (bWebViewOverview) {
        webView.getSettings().setLoadWithOverviewMode(false);
        webView.setInitialScale(webViewInitialZoom);
        Timber.d("WebView Initial Scale: %s%%", webViewInitialZoom);
    } else {
        webView.setInitialScale(Preferences.Default.PREF_WEBVIEW_INITIAL_ZOOM_DEFAULT);
        webView.getSettings().setLoadWithOverviewMode(true);
    }

    if (BuildConfig.DEBUG) WebView.setWebContentsDebuggingEnabled(true);


    webClient = getWebClient();
    webView.setWebViewClient(webClient);

    // Download immediately on long click on a link / image link
    if (Preferences.isBrowserQuickDl())
        webView.setOnLongClickListener(v -> {
            WebView.HitTestResult result = webView.getHitTestResult();

            String url = "";
            // Plain link
            if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE && result.getExtra() != null)
                url = result.getExtra();

            // Image link (https://stackoverflow.com/a/55299801/8374722)
            if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
                Handler handler = new Handler();
                Message message = handler.obtainMessage();

                webView.requestFocusNodeHref(message);
                url = message.getData().getString("url");
            }

            if (url != null && !url.isEmpty() && webClient.isBookGallery(url)) {
                // Launch on a new thread to avoid crashes
                webClient.parseResponseAsync(url);
                return true;
            } else {
                return false;
            }
        });


    Timber.i("Using agent %s", webView.getSettings().getUserAgentString());
    chromeVersion = getChromeVersion(this);

    WebSettings webSettings = webView.getSettings();
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    webSettings.setUserAgentString(Consts.USER_AGENT_NEUTRAL);

    webSettings.setDomStorageEnabled(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadWithOverviewMode(true);

    CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    SwipeRefreshLayout refreshLayout = findViewById(R.id.swipe_container);
    if (refreshLayout != null) refreshLayout.addView(webView, layoutParams);
}
 
源代码20 项目: react-native-GPay   文件: ReactWebViewManager.java
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected WebView createViewInstance(ThemedReactContext reactContext) {
  ReactWebView webView = createReactWebViewInstance(reactContext);
  webView.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onConsoleMessage(ConsoleMessage message) {
      if (ReactBuildConfig.DEBUG) {
        return super.onConsoleMessage(message);
      }
      // Ignore console logs in non debug builds.
      return true;
    }

    @Override
    public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
      callback.invoke(origin, true, false);
    }
  });
  reactContext.addLifecycleEventListener(webView);
  mWebViewConfig.configWebView(webView);
  WebSettings settings = webView.getSettings();
  settings.setBuiltInZoomControls(true);
  settings.setDisplayZoomControls(false);
  settings.setDomStorageEnabled(true);

  settings.setAllowFileAccess(false);
  settings.setAllowContentAccess(false);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    settings.setAllowFileAccessFromFileURLs(false);
    setAllowUniversalAccessFromFileURLs(webView, false);
  }
  setMixedContentMode(webView, "never");

  // Fixes broken full-screen modals/galleries due to body height being 0.
  webView.setLayoutParams(
    new LayoutParams(LayoutParams.MATCH_PARENT,
      LayoutParams.MATCH_PARENT));

  setGeolocationEnabled(webView, false);
  if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    WebView.setWebContentsDebuggingEnabled(true);
  }

  return webView;
}