アプリにローカルのhtmlファイルを表示するWebViewがあります。shouldOverrideUrlLoading()メソッドで処理しているPDFファイルへのリンクがありますが、そうすることで、ページのhttp://リンクがデバイスのブラウザーではなくWebViewに読み込まれるようになります。
以下のコードはPDFファイルを認識し、これは正常に機能しますが、外部URLをクリックすると、Chromeブラウザで同じURLの2つのタブが開きます。1つだけ開くにはどうすればよいですか?
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains(".pdf")) {
// Remove the file:///android_asset/ text in url
String tmpUrl = url.replace("file:///android_asset/", "");
PdfHandler pdf = new PdfHandler(mContext);
pdf.openPdf(tmpUrl);
return true;
}
else{
// 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;
}
}
}
ありがとう