15

I have a requirement like this and something similar to that has been implemented by Android Pit app-store.

I need to check if the Android app has been installed on the device using a mobile web page (PHP and JS), and if installed launch the app immediately.

These are the intermediate pages used by Android pit.

When app has not been installed - http://www.androidpit.com/en/android/market/app-center-mobile?pname=com.ocito.laredoute

When app has been already installed - http://www.androidpit.com/en/qrdl/com.mobage.ww.a692.Bahamut_Android

Does anyone know how to implement this?

halfer
  • 19,824
  • 17
  • 99
  • 186
Shaolin
  • 2,541
  • 4
  • 30
  • 41
  • does androidpit know of installed apps that where not installed through androidpit itself or marked as installed in the androidpit user account? my first guess is, they are checking their own database instead of the device itself. – Jan Prieser Oct 12 '12 at 10:47
  • No. It's not like that, It's there app centre app so they check if that app has been installed or not. The same scenario only i also need. – Shaolin Oct 12 '12 at 10:59
  • like i guessed, they check their own database which is fed through their app centre app. – Jan Prieser Oct 12 '12 at 11:42
  • I got some links, http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app/3472228 https://gist.github.com/2662899 – Shaolin Oct 15 '12 at 11:21

5 Answers5

22

Fortunately, this is not possible, for obvious privacy reasons.

The closest that you can do is in the application, have an activity that has an <intent-filter> for some URL structure, and have a link in the mobile Web site to a matching URL.

If the user clicks the link and the app is installed, the activity will be a chooser option for the user.

If the user clicks the link and the app is not installed, or they choose to stick with their Web browser from the chooser, whatever Web page exists at that URL will be displayed (E.g., instructions of how to download the app).

Shaolin
  • 2,541
  • 4
  • 30
  • 41
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 2
    @Unicorn: If the app is not installed, clicking the link will bring up a regular Web browser on whatever the URL is. Assuming that you control the URL (e.g., it points to your Web server), you can have that URL return a Web page that explains the merits of downloading your app, perhaps even with a `market:` link to it. However, it is possible that the user will still see that Web page even if the app is installed, as they might choose a Web browser in the chooser, rather than choosing your app. So, make sure the prose on that page covers this possibility. – CommonsWare Oct 15 '12 at 11:49
22

There is a way to achieve this. Found this answer

You cannot detect if a particular application is installed, for security and privacy reasons. But you can do a trick to open the app if it's installed or open its Google Play page if it isn't.

To do that, you must create an intent-filter on your app's main activity, to open it when a given URL is called. Like this:

<activity android:name=".MainActivity >
    <intent-filter>
        <data
            android:host="www.myurl.com"
            android:pathPrefix="/openmyapp"
            android:scheme="http" >
        </data>

        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.VIEW" />
    </intent-filter>
</activity> 

Explaining: when the user navigates to http://www.myurl.com/openmyapp, if the app is installed, an intent will be created and the Activity will be shown.

But what if the user doesn't have the app installed? Then you need to create a redirect page on your http://www.myurl.com/openmyapp/index.html. When the user reaches this address, your server must redirect to market://details?id=com.your.app.package.

This way, when no Intent is created after the user navigates to http://www.myurl.com/openmyapp, the web server will call another URL. That URL, in turn, will open Google Play on the device, directly on the app's page.

halfer
  • 19,824
  • 17
  • 99
  • 186
AL̲̳I
  • 2,441
  • 4
  • 29
  • 50
1

In case of

<data
    android:host="www.myurl.com"
    android:pathPrefix="/openmyapp"
    android:scheme="http" >
</data>

it will ask user by which way open the content.

enter image description here

To avoid this or to avoid connect your app to some url you can do another trick to implement this using PHP and JS.

  1. You must create an intent-filter on your app's main activity like this:
<intent-filter android:label="filter_react_native">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="MyCustomScheme" android:host="MyCustomHost" />
</intent-filter>
  1. Create PHP file redirect_to_app.php which will work in case user have the app installed.
<?php
header('Location: MyCustomScheme://MyCustomHost');
  1. Create HTML/PHP file check_redirect_to_app.php which must be shown for users which didn't install your app yet.
...
<a href="https://play.google.com/store/apps/details?id=YOUR_APP_PACKAGE_NAME">Please install the application</a>
...

<script>
    location.href = '...redirect_to_app.php';
</script>
  1. Redirect users to check_redirect_to_app.php. check_redirect_to_app.php will try to redirect to MyCustomScheme://MyCustomHost automatically. In case it will not find such a app, it will coninue to show check_redirect_to_app.php content.
Mher
  • 985
  • 9
  • 23
  • Just one note: `location.href = 'MyCustomScheme://MyCustomHost';` doesn't work, so `redirect_to_app.php` is required. – Mher Jul 09 '19 at 21:28
1

You can do this using the browser on your phone

 intent://scan/#Intent;scheme=clashofclans;package=com.supercell.clashofclans;S.browser_fallback_url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.supercell.clashofclans&amp;%26referrer%3Dkinlan;end

 intent://scan/#Intent;scheme=vnd.youtube://www.youtube.com/watch?v=QXhoNI4O99A;package=com.google.android.youtube;S.browser_fallback_url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.google.android.youtube&amp;%26referrer%3Dkinlan;end

you can try this too

the application in question must have the scheme in the AndroidManifest clash of clans// or other scheme

AllanRibas
  • 678
  • 5
  • 14
0

there's a better trick. you are going to see if URL returns a 404, means not found. Where URL will not work if there is no app installed.

chris_r
  • 2,039
  • 1
  • 22
  • 22