swarnima
swarnima

Reputation: 89

deep linking to redirect to play store if app not installed

I am using the concept of deep linking in my app what i actually want is when i share the link from my app its working fine it goes to the activity which i want to open in my app but problem is when a user is not having this app this link is opening through phone's browser and error is displayed of not found but i want to go to the play store if app is not installed. what approach should i try....

manifest.xml:

<activity
        android:name="package"
        android:configChanges="orientation|screenSize|keyboardHidden">
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http"
            android:host="www.example.com"
            android:pathPrefix="/Home_page"></data>
        <data android:scheme="https"
            android:host="www.example.com"
            android:pathPrefix="/Home_page"></data>

    </intent-filter>
 </activity>

Upvotes: 7

Views: 22957

Answers (2)

Aayush Mathur
Aayush Mathur

Reputation: 97

I was looking for something like this few months back and I found out that unless you actually have a server from where you can direct the link to the Play Store, you cant do it normally. For this the best solution I found out was Firebase Dynamic Links, they do the checking on their side and takes your users to the play store if they have not installed the app. Plus it also provides analytics of the number of clicks and the sources and some information about your users.

Upvotes: 4

Vladyslav Matviienko
Vladyslav Matviienko

Reputation: 10871

Probably there is a better and more correct way, but you can do as follows:

  1. On your server define some request parameter to check, like www.example.com/your_url?playmarket=true, and make the links to be shared including it.
  2. In your app, when opening this link just remove that ?playmarket=true before processing the url.
  3. on your server check, if ?playmarket=true is present, then just redirect to your app's page in google play.

So this way you will be able to open the links in your app, and if the link is opened in browser - your server will redirect user to google play.

Another way to check if you need to redirect - set your app's user-agent to some specific string, like MyAppsAgent, and check the user agent on the serve. If it differs from MyAppsAgent` - redirect to google play.

Upvotes: 7

Related Questions