Reputation: 639
In activity 1 I got a web view. For each link to a external website (e.g. if you are on facebook and you click a link to amazon) should activity 2 be started.
Activity 2 contains also a web view. This web view should load the clicked link from activity 1.
I read about the "shouldOverrideUrlLoading" method. But the new one is provided in a too high api level. And the deprecated one triggers for each click in the web view (also if you dont leave the site). I could filter - but it's still deprecated.
So I tried this way:
WebView view = (WebView) rootView.findViewById(R.id.webView);
view.setWebViewClient(new WebViewClient());
view.getSettings().setSupportMultipleWindows(true);
view.setWebChromeClient(new WebChromeClient() {
@Override public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg)
{
Intent externalLinkIntent = new Intent(getActivity(), ExternalLinkActivity.class);
Bundle bundle = new Bundle();
bundle.putString("externalLink", "externalLinkGoesHere");
externalLinkIntent.putExtras(bundle);
startActivity(externalLinkIntent);
return true;
}
});
This method triggers only if I really LEAVE the actual site. But for me it is not possible to get out the damn url of the resultMsg. Normally it is used to call the default chrome browser for external links.
Are there any ideas or other ways?
Thanks!
Upvotes: 1
Views: 908
Reputation: 639
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
String targetUrl = view.getHitTestResult().getExtra();
//More actions
}
Upvotes: 1