简体   繁体   English

webview活动链接无法在浏览器中打开

[英]webview activity links not opens in browser

inside the webpage of my webview activity their is download link I want the links when clicks open in dfault browser to start download 在我的webview活动的网页内是下载链接,我希望在dfault浏览器中单击打开时开始下载链接

how to make all links inside the webview activity opens in browser? 如何使webview活动内的所有链接在浏览器中打开? pls help 请帮助

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class C13 extends Activity {
    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_c13);

        webView = (WebView) findViewById(R.id.webc13);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("https://sites.google.com/site/abdwou/1st-bio");
        webView.setWebViewClient(new WebViewClient());
    }

}
WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl(http://www.playbuzz.org);

you dont have to include this code // webview.setWebViewClient(new WebViewClient()); 您不必包含此代码// // webview.setWebViewClient(new WebViewClient()); instead u need to use d code below 相反,您需要在下面使用d代码

webview.setWebViewClient(new WebViewClient(){
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        String url2="http://www.playbuzz.org/";
         // all links  with in ur site will be open inside the webview 
         //links that start ur domain example(http://www.example.com/)
        if (url != null && url.startsWith(url2)){
            return false;
            } 
       // all links that points outside the site will be open in a normal android browser
      else  {
            view.getContext().startActivity(
            new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;
            }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM