在我的webview活动的网页内,他们是下载链接我想在dfault浏览器中点击打开以开始下载时的链接
如何在浏览器中打开webview活动中的所有链接?请帮忙
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());
}
}
答案 0 :(得分:6)
WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl(http://www.playbuzz.org);
你不必包含这个代码// webview.setWebViewClient(new WebViewClient());相反,你需要使用下面的代码
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;
}
}
});