Android DeepLink 外部唤醒应用简单实现(通过浏览

2018-01-17  本文已影响1063人  简简单单敲代码

Deep Link是什么

Deep Link,又叫deep linking,中文翻译作深层链接。

新建一个 DeepLinkActivity,然后在AndroidManifest注册一下。注意的点是intent-filter怎么去写,拿淘宝天猫为例。反编译一下也可以看出他们是怎么写的。

intent-filter可以有多个,其中每一个intent-filter可以固定加上

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />

然后data中才是你需要想要什么样的 url 可以打开你的 app.比如淘宝天猫打开。比如再加上pcxapp只要是pcxapp://开头的都可以打开

AndroidManifest中注册 DeeplinkActivity 参考如下。

  <activity
            android:name=".DeepLinkActivity"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Translucent.NoTitleBar">
        
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data android:scheme="pcxapp" />
            </intent-filter>
        </activity>

最后你可以在DeeplinkActivity 中取到 urlurl = getIntent().getDataString();再通过 url 进行逻辑判断就实现了。

上一篇 下一篇

猜你喜欢

热点阅读