tags:

views:

72

answers:

2

Hi, I want to launch an application in the phone by clicking its link in the browser..How can I do this???

+1  A: 

Have your application respond to a tailor-made intent described in your manifest file, like this :

<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="myserver.com" android:pathPrefix="/directory"/>

Your application will then respond to links http://myserver.com/directory.

In your activity, you can then get the url by calling .getData on the intent.

Jean
@Jean:can you give the complete code code for launching the installed package from the browser
antony
I hav tried the above code ..but its not working
antony
A: 

As Jean described writing your own intent filter is the way to go, but you probably want to use your own private scheme based on your app name, as the built in browser will probably intercept http in many cases.

<activity android:name=".main"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar"
    android:configChanges="orientation|keyboardHidden"
    android:launchMode="singleTask"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustPan">
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="helloworld" />
</intent-filter>

Then to trigger it, in html:

<a href="helloworld://somedata/urlformated">Click here to launch app</a>

To access the url data, in your activity onResume, do something like:

Uri launchURI = getIntent().getData();

You can parse out the data using the various Uri methods. Keep in mind that there will be an Intent even for normal launch so you need to handle that case. Doing this in onResume supports both the case where your app was already running and was launched.

cistearns
@cistearns:wow..!!!!!,,,,its working smoothly...thanxxxxx a lot....
antony
@cistearns:plz tell me how to get the url in my application
antony
@antony see edits to my original answer.
cistearns
@cistearns:thanz....its working...just as i need...bt i want to show in mobile browser whether that application is installed or not...if not installed show that in an alert......is that posible??
antony