Open link for pop-up / external site in current web view

I am currently writing a webview, it first loads the Twitter page (say NHL, http://twitter.com/nhl ) as you can see, you can find a tweet for the NHL, and each NHL tweet has a different link for the user's click, for example . bit.ly/ujcNZo

in my web browser, if I click this link (i.e. bit.ly/ujcNZo), my web view, after 1 second, does not display anything except the slit icon on a white colored background, it should load the content, but it doesn’t did.

after some time of investigation, I think this is due to the fact that the link in tweet (i.e. bit.ly/ujcNZo) actually opens the link in a separate window (pop-up?), and not on the current page where the link is published, I confirmed this by going to the NHL twitter page on a browser on my laptop.

My question is: 1. is there a way that I can load the contents of an external link (bit.ly/ ujcNZo, for example) in my current webview?

+3
source share
1 answer

You can control this through the WebViewClient class. Just add it and override the default implementation to get the configuration you need, then set it as a client for your current webview.

activity

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // set the webViewClient to a new instance of your custom WebViewClient webview.setWebViewClient(new WebActivityClient( this )); } 

User client

 /** WebViewClient class for WebView in WebActivity */ private class WebActivityClient extends WebViewClient { public static final String TAG = "WebActivityClient"; private Context context; /** Constructor used to grab the context */ public WebActivityClient( Context context ) { this.context = context; } /** Override to load every link within the page inside this webview instead of using * android default application * #7 http://developer.android.com/resources/tutorials/views/hello-webview.html */ @Override public boolean shouldOverrideUrlLoading( WebView view, String url ) { view.loadUrl(url); return true; } } 

Hope this helps!

+2
source

Source: https://habr.com/ru/post/1275852/


All Articles