I convert WordPress website to android app, in my website lots of external links i need to open external links browser like telegram, in telegram all external links open in external browser in the app
Question posted in Telegram API
A comprehensive official documentation can be found here.
A comprehensive official documentation can be found here.
3
Answers
Problem SOlved guys thanks for your replays
Source (from sven)
});
You can add a
WebViewClient
to your webview and override theshouldOverrideUrlLoading
method. This will give you a callback when a link is clicked and you can inspect the url and decide if you want to open in the webview or open it in the external browser.For example something like:
As @peshkira has given a good solution, but I would suggest to use CustomTab.
With Custom Tabs you can get instance of browser without creating a web view. As it provide navigation awareness, the browser delivers a callback to the application upon an external navigation. You can modify and update following –
Setup for CustomTab –
In your code, Open a CustomTab –
You can save up to 700 ms when opening a link with the Custom Tabs by connecting to the service and pre-loading the browser.
Most browser do support CustomTab like Chrome, Samsung Mobile Broswer, Microsoft Edge etc.
Please follow Custom Tabs Best Practices. Here is a gitHub example.
Edit
As you mentioned in your comment "every post have 1 external link", then you following options –
WebView
to open linkCustomTab
to open instance of browserI think behavior of all three is very well explained via this gif.
Now, to show all the posts in your app, I believe you are using a
RecycleView
, so you can decide from three choices, you can listen for click on one of the post by using a click listener on that post, something like follows –Now in the body of your method
handleClickOnLink(String postUrl)
you can use your code to decide how you want open the link.As I have mentioned above, Using
CustomTab
will be one of the choices, which I think will be a good option in this case, so you can have an implementation of method as follows –If there is a device with a browser which doesn’t support
CustomTab
then device default browser will be open.Result will be something as follows –
Happy Coding !