Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable deep-linking in WebView on Android app?

Tags:

I'm trying to implement deep linking in android app.

When I click the deep linking of custom url (xxxx://repost?id=12) on Android browser like Chrome, my app opens up and works very well.

Problem is, in the app, there's a webView widget, and I want to the deep-linking work there too.

Currently, it's showing Can't connect to the server error.

Thanks in advance.

like image 600
adeltahir Avatar asked Sep 04 '14 18:09

adeltahir


People also ask

How do I enable deep link on Android?

Android Studio makes it very easy to test deep links. Click Run > Edit Configurations to edit the configuration of the project. Open the General tab at the top and enter the URI in the Deep Link field in the Launch Options section.

How do I integrate a deep link app on Android?

Select Open deep link URL in a browser option. Click Next. For Android, select Open the deep link in your Android app. Then select your app from the dropdown, in this case the com.

Can you deep link into an app?

Deep linking, in simplest terms, is the ability to link directly to content in your app. Instead of simply launching the app and leaving users at the home screen, tapping on a deep link brings users to a specific screen within your app. Think product pages, profiles, new content, or shopping carts.

How do I create a deep link for an app?

To use the tool, log in to your Adjust dashboard and open the Menu, where you'll see the 'Deeplink Generator' as an option. Click to open, and you'll find a page to input the information required to create your deep link. Then simply copy and paste into whichever campaign you've set up.


1 Answers

This is the problem with android web view as this treats everything as URL but other browser like chrome on mobile intercepts the scheme and OS will do the rest to open the corresponding app. To implement this you need to modify your web view shouldOverrideUrlLoading functions as follows:

 @Override  public boolean shouldOverrideUrlLoading(WebView view, String url) {         LogUtils.info(TAG, "shouldOverrideUrlLoading: " + url);         Intent intent;          if (url.contains(AppConstants.DEEP_LINK_PREFIX)) {             intent = new Intent(Intent.ACTION_VIEW);             intent.setData(Uri.parse(url));             startActivity(intent);              return true;         }   } 

In above code replace AppConstants.DEEP_LINK_PREFIX with your url scheme eg.

android-app://your package

Hope this helps!!

like image 77
Pranav Avatar answered Sep 28 '22 19:09

Pranav