美文网首页
Android DeepLink 外部唤醒应用简单实现(通过浏览

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

作者: 简简单单敲代码 | 来源:发表于2018-01-17 14:48 被阅读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 进行逻辑判断就实现了。

相关文章

网友评论

      本文标题:Android DeepLink 外部唤醒应用简单实现(通过浏览

      本文链接:https://www.haomeiwen.com/subject/jgcuoxtx.html