最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中的深度鏈接技術(shù)實(shí)戰(zhàn)

 更新時(shí)間:2022年03月23日 09:59:55   作者:星星同學(xué)  
本文主要介紹了Android中的深度鏈接技術(shù)實(shí)戰(zhàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

前言

日常中,我們經(jīng)常需要從瀏覽器中的網(wǎng)頁(yè)或者從其它APP中直接打開我們的APP,我們就需要使用到深度鏈接技術(shù)。實(shí)現(xiàn)方式分別是 Dee pLinks 和 APP Links。

Deep Links

deep links是谷歌支持的一種打開app指定頁(yè)面的方式,常用于從H5頁(yè)面跳轉(zhuǎn)至app目標(biāo)頁(yè)面。其對(duì)應(yīng)指定頁(yè)面的匹配規(guī)則是按照URI來匹配的。常見URI格式如下圖:

示例

  • H5測(cè)試頁(yè)面
<html>
<a  rel="external nofollow" >點(diǎn)擊喚起app</a>
<a  rel="external nofollow" >點(diǎn)擊喚起app</a>
<a href="abc://demo.deaven.com:2003/test/data?params1=value1&params2=value2" rel="external nofollow" >點(diǎn)擊喚起app</a>
</html>

如上

  • scheme = http、https、abc。 DeepLink中 scheme 可自定義
  • host = demo.deaven.com
  • port = 2003
  • path = test/data
  • 傳遞參數(shù)(key-value): params1 : value1 params2 : value2
  • Android配置
 <activity android:name=".MainActivity"
           android:exported="true"
           android:launchMode="singleTask">
            <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="http" /> 
                <data android:scheme="https" />
                <data android:scheme="abc" />
                <data android:host="demo.deaven.com"/>
                <data android:port="2003"/>
                <!--表示匹配 Path 以/test 開頭的uri,此項(xiàng)可以不寫-->
                <!-- 注意 "/" 在pathPrefix中是必須的-->
                <data android:pathPrefix="/test"/>

            </intent-filter>
        </activity>

3.Activity中解析Intents

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Uri uri = getIntent().getData();
    String scheme = uri.getScheme(); // http、https、abc
    String host = uri.getHost(); // demo.deaven.com
    String path = uri.getPath(); // test/data
    String query = uri.getQuery(); // params1=value1&params2=value2
    String value1 = uri.getQueryParameter("params1"); 
    String value2 = uri.getQueryParameter("params2");
}

為了更好的管理以及用戶體驗(yàn),app中可以聲明一個(gè)中間頁(yè)根據(jù)參數(shù)統(tǒng)一分發(fā)跳轉(zhuǎn)請(qǐng)求。

注意事項(xiàng)

  • scheme為 htttp/https 開頭的uri,部分瀏覽器和手機(jī)ROM 并不能鏈接至APP,而是在瀏覽器中打開了對(duì)應(yīng)的鏈接。所以做Deep Links時(shí)建議全部采用自定義Scheme的形式。

  • 在詢問是否用APP打開對(duì)應(yīng)的鏈接時(shí),如果選擇了“取消”并且“記住選擇”被勾上,那么下次你再次想鏈接至APP時(shí)就不會(huì)有任何反應(yīng)!!!

  • 不同的host不要寫在同一個(gè)Intent Filter中,最好為每種匹配規(guī)則新建一個(gè)Intent Filter

App Links

Android在Android 6.0 (API level 23) 及以后加入了App Links , 當(dāng)用戶點(diǎn)擊對(duì)應(yīng)的URI 時(shí),會(huì)直接啟動(dòng)對(duì)應(yīng)的APP,不會(huì)再出現(xiàn)類似Deep Links 中是否打開app 的對(duì)話框出現(xiàn)。

Intent Filter

 <activity android:name=".MainActivity"
           android:exported="true"
           android:launchMode="singleTask"
           android:autoVerify="true">
            <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="http" /> 
                <data android:scheme="https" />
                <data android:host="demo.deaven.com"/>
                <data android:port="2003"/>
                <!--表示匹配 Path 以/test 開頭的uri,此項(xiàng)可以不寫-->
                <!-- 注意 "/" 在pathPrefix中是必須的-->
                <data android:pathPrefix="/test"/>

            </intent-filter>
        </activity>
  • Intent Filter和Deep Links 類似 但是 scheme只能使用 htttp 或 https 不支持自定義scheme。

  • android:autoVerify="true" 會(huì)讓APP自動(dòng)在所列的host中去驗(yàn)證,如果驗(yàn)證成功,APP將成為匹配URI默認(rèn)打開方式。

配置 assetlinks.json

如不能翻墻,可復(fù)制下方代碼修改為自己參數(shù),生成 assetlinks.json文件 ,json文件名只能是 assetlinks 不能自定義

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target" : { "namespace": "android_app", "package_name": "com.deaven.link",
               "sha256_cert_fingerprints": [""14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5""] }
}]

2.部署assetlinks.json

我們的host為demo.deaven.com,那么我們就需將assetlinks.json放到https://demo.deaven.com/.well-known/assetlinks.json并可以正常訪問。你也可以在 https://developers.google.com/digital-asset-links/tools/generator檢查服務(wù)器上assetlinks.json是否可訪問如下圖:

3.Activity中解析Intents 類似 Deep Links

參考文檔

https://www.jianshu.com/p/1632be1c2451

到此這篇關(guān)于Android中的深度鏈接技術(shù)實(shí)戰(zhàn)的文章就介紹到這了,更多相關(guān)Android 深度鏈接內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

宁明县| 隆安县| 鸡东县| 汉阴县| 惠水县| 敖汉旗| 启东市| 商洛市| 哈密市| 清水河县| 郯城县| 和田县| 措美县| 临武县| 张家界市| 九寨沟县| 宁强县| 隆林| 吴江市| 读书| 张北县| 额尔古纳市| 库车县| 宁津县| 安龙县| 鄂托克旗| 曲阳县| 色达县| 赤城县| 东明县| 南昌县| 祥云县| 九台市| 鄢陵县| 河北区| 上高县| 商河县| 鄂伦春自治旗| 龙口市| 广南县| 中卫市|