Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if Android app has been installed on the device using a mobile web page - PHP and JS

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?

like image 654
Shaolin Avatar asked Oct 12 '12 10:10

Shaolin


People also ask

How do I know if an app is installed Android?

Call the below function appInstalledOrNot() with the package name of the app installed on the ANDROID Device as a string parameter. This function returns true if the app is installed otherwise returns false. super . onCreate(savedInstanceState);

Is it possible to check with my website if an app is installed?

Your website can check if your Android app is installed.


2 Answers

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).

like image 198
CommonsWare Avatar answered Oct 05 '22 21:10

CommonsWare


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.

like image 24
AL̲̳I Avatar answered Oct 05 '22 19:10

AL̲̳I