Search in sources :

Example 1 with WebViewClient

use of android.webkit.WebViewClient in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    browser = (WebView) findViewById(R.id.browser);
    browser.getSettings().setJavaScriptEnabled(true);
    browser.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return (true);
        }
    });
    visit(getIntent());
}
Also used : WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) SuppressLint(android.annotation.SuppressLint)

Example 2 with WebViewClient

use of android.webkit.WebViewClient in project cw-omnibus by commonsguy.

the class BrowserDemo4 method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    browser = (WebView) findViewById(R.id.webkit);
    browser.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return (true);
        }
    });
    browser.loadUrl("http://commonsware.com");
}
Also used : WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 3 with WebViewClient

use of android.webkit.WebViewClient in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" })
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mgr = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    light = mgr.getDefaultSensor(Sensor.TYPE_LIGHT);
    wv = (WebView) findViewById(R.id.webkit);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.addJavascriptInterface(jsInterface, "LIGHT_SENSOR");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        wv.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageFinished(WebView view, String url) {
                initPort();
            }
        });
    }
    wv.loadUrl(URL);
}
Also used : WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) SuppressLint(android.annotation.SuppressLint)

Example 4 with WebViewClient

use of android.webkit.WebViewClient in project materialistic by hidroh.

the class WebFragmentTest method testAdBlocker.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Test
public void testAdBlocker() {
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    WebViewClient client = shadowOf(webView).getWebViewClient();
    assertNull(client.shouldInterceptRequest(webView, "http://google.com"));
    assertNull(client.shouldInterceptRequest(webView, "http://google.com"));
    assertNotNull(client.shouldInterceptRequest(webView, "http://page2.g.doubleclick.net"));
    assertNotNull(client.shouldInterceptRequest(webView, "http://page2.g.doubleclick.net"));
}
Also used : WebView(android.webkit.WebView) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) WebViewClient(android.webkit.WebViewClient) Test(org.junit.Test) SuppressLint(android.annotation.SuppressLint)

Example 5 with WebViewClient

use of android.webkit.WebViewClient in project remusic by aa112901.

the class TopFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_top, container, false);
    webView = (WebView) view.findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36");
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // 根据传入的参数再去加载新的网页
            view.loadUrl(url);
            // 表示当前WebView可以处理打开新网页的请求,不用借助系统浏览器
            return true;
        }
    });
    webView.loadUrl("http://music.163.com/#/discover/toplist?id=19723756");
    return view;
}
Also used : WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebViewClient (android.webkit.WebViewClient)247 WebView (android.webkit.WebView)229 WebSettings (android.webkit.WebSettings)77 View (android.view.View)71 WebChromeClient (android.webkit.WebChromeClient)69 SuppressLint (android.annotation.SuppressLint)61 Intent (android.content.Intent)60 Bitmap (android.graphics.Bitmap)59 WebResourceRequest (android.webkit.WebResourceRequest)35 TextView (android.widget.TextView)26 LinearLayout (android.widget.LinearLayout)22 WebResourceError (android.webkit.WebResourceError)21 WebResourceResponse (android.webkit.WebResourceResponse)16 Uri (android.net.Uri)15 SslError (android.net.http.SslError)13 Bundle (android.os.Bundle)13 Toolbar (android.support.v7.widget.Toolbar)13 KeyEvent (android.view.KeyEvent)13 SslErrorHandler (android.webkit.SslErrorHandler)13 TargetApi (android.annotation.TargetApi)12