特定のサイトのすべてのWebページ(たとえば、www.yahoo.com)をWebビューで開き、他のすべてのWebページをdefaultbrowserで開くアプリを作成しようとしています。これが私が使用しているコードですが、完全に機能させることはできません。
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("http://www.yahoo.com")) {
// This is my web site, so do not override; let my WebView load
// the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch
// another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
このコードは機能するはずですが、yahooをロードすると、外部のブラウザに移動します。どんな助けでもいただければ幸いです。ありがとう!