简体   繁体   中英

Android WebView: How do I allow deep links?

When I click on a link within my WebView , it behaves as expected - it opens the link within the WebView .

However, if an app can handle that link, I would like to open that app instead. For example, if I tap on a Twitter link, I would like it to open Twitter, else open in-app.

This is how Google Chrome on Android behaves. This is also how WKWebView , the iOS equivalent of WebView , also behaves.

How would I go about implementing that? I have attempted to implement the solutions here but now my app always wants to open the system browser.

Deep Links as handled by OS itself. You just need to implement it properly. For example, in Android if you want to open the following url

http://twitter.com/intent/tweet?text=YOUR_TEXT

it will open the twitter app if the app is installed in your phone. Otherwise it will be opened in your browser.

But in case of iOS you have to specify the URL Scheme for opening in another app. Check the following url

twitter://post?message=YOUR_MSG

So when implementing this SO answer, you should also consider about the URL Schemes.

You should also keep in mind that webview in the application are implemented so that you don't have to open the browser app and no urls are exposed. If you want to open another app, you must consider opening the url in browser from your app so that OS can handle the rest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM