Launching an application using browser?
I want t开发者_Go百科o launch an application in the phone by clicking its link in the browser..How can I do this???
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.
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.
精彩评论