Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

Detect from browser if a specific application is installed in Android

I'm looking for a way to find out if a specific application is installed from a client-side web browser. The platform is Android.

For example I write my own web site and I write my own application, now I want to when user comes to my own site from Android phone Browser. The Browser look if the application is already installed on the phone and if not suggest to install application. Can I do that ?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a way to achieve this.

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.LAUNCHER" />
        </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 webserver will call another URL. That URL, in turn, will open Google Play on the device, directly on the app's page.

Hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...