How to open my application directly by clicking on

2019-07-18 07:45发布

I am looking for a solution so far, i.e When user clicks on a link from his mail box My Application should open if My Application is already installed in his device without asking user to choose options with Just Once and Always .For example, clicking a URI in an email from a bank might result in a dialog asking the user whether to use the browser, or the bank's own app, to open the link, But in my case my application should open directly without asking to choose any option. I have implemented my application as follows: My manifest file as AndroidManifest.xml

   <activity android:name=".WelcomeActivity"
        android:label="@string/app_name">
        <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="www.example.com"
                android:scheme="http"
                android:pathPrefix="/blog"></data>
        </intent-filter>
    </activity>

My example url is http://www.example.com/blog

I would like to open my application if user clicks on above link. Please help me with sample code with steps.

1条回答
Rolldiameter
2楼-- · 2019-07-18 08:12

This feature is only available on Android devices running at least Marshmallow (6+) and is referenced as App Link throughout the Android documentation.

To fully implement this feature, it requires you to own the corresponding url and add a configuration file at this address: https://www.example.com/.well-known/assetlinks.json. The file content is described in the documentation (contains the package name and its signature).

Then, modify your intent-filter as follow to enable the auto-verify feature:

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https" android:host="www.example.com" android:pathPrefix="/blog" />
</intent-filter>

You should definitely read the documentation about this feature. It contains a lot of usefuls tips to test your implementation.

查看更多
登录 后发表回答