Home > OS >  How to switch from webview to another application
How to switch from webview to another application

Time:10-14

Good day, please tell me, I am implementing my own browser, there is a webview and it is necessary that the user, when searching for the information he needs, switch from the webview to other applications that are installed or can be installed on the phone, for example, if the user clicks on a link to YouTube when viewing the webview , then the YouTube application will open through the intent, I implemented such logic through the webview client (the shouldOverrideUrlLoading function) but I ran into a problem in which either the search in the webview works for me or the browser redirects any search to another browser. If you remove the line of code (mWebView?.webViewClient =) and leave (object : WebViewClient() {) then the webview will open intents for everything, but if you leave both lines, then intents for third-party applications will not open in the webview, how can you merge data webview features and what am I missing?

![Text]: (https://i.imgur.com/KyRtF7e.png)

CodePudding user response:

hmmm normally you can use custom tab and it will handle the deeplinks heres what i have for you first you use @Override public boolean shouldOverrideUrlLoading(WebView view, String url) {} then you create intent Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); then you query the Apps that can handle it PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> resolvedActivities = packageManager.queryIntentActivities(browserIntent , 0); you can Use loadLabel() on the ResolveInfo to get a "user friendly label" i don't have the full solutation as it is new for me but if you only need the webview to be part of your app only use ChromeTab hope this can help

  • Related