开发者

About starting Android app from an URL

I 开发者_JAVA技巧am trying to figure out how to start an app from a URL, and how I should write that URL.

I have the following code in my AndroidManifest:

<activity android:name=".MyActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"></action>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.LAUNCHER"></category>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
        <data android:host="my.app" android:scheme="http"></data>
    </intent-filter>
</activity>

I used a URL as explained in this answer, but nothing happens.

Please let me know if my intent is well written, and how I should write the URL that calls that app, and note that I need to call my "Main" Activity.


You need to have two <intent-filter> elements for this <activity>. One will be for MAIN and LAUNCHER. The other will be for VIEW, BROWSABLE/DEFAULT, and your <data> element:

<activity android:name=".MyActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"></action>
        <category android:name="android.intent.category.LAUNCHER"></category>
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
        <data android:host="my.app" android:scheme="http"></data>
    </intent-filter>
</activity>

Then, http://my.app should launch your activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜