DeepLink 與 Uri跳轉

DeepLink 與 Uri跳轉

  • DeepLink是指Google提出的採用 deepLink,配置的 跳轉方式
  • Uri是指 傳統的在 AndroidManifest中聲明 IntentFilter的 data,設置段鏈接的方式跳轉
結論:

採用scheme非http的Uri跳轉更加方便

  • http 跳轉的 deepLink和Uri是一樣的效果
  • scheme爲 http的 Uri和 DeepLink跳轉,都要在設置中授權,默認不授權,無法跳轉
  • Uri跳轉 scheme 不是http 可以直接跳轉,無需授權
  • Uri跳轉 scheme 不是http 在筆記本等 應用中,不會高亮

DeepLink

  • 需要引入navigation 庫

Manifest 文件

//***
    <activity android:name="com.example.android.navigationadvancedsample.MainActivity">
        <nav-graph android:value="@navigation/list" />
    </activity>
    
//***

res/navigation/list.xml

<navigation>
    <fragment
        android:id="@+id/userProfile"
        android:name="com.example.android.navigationadvancedsample.listscreen.UserProfile"
        android:label="@string/title_detail"
        tools:layout="@layout/fragment_user_profile">
        <deepLink
            android:id="@+id/deepLink"
            app:uri="www.example.com/user/{userName}"
            android:autoVerify="true"/>
        <argument
            android:name="userName"
            app:argType="string"/>
    </fragment>
</navigation>

Uri

  • 不需要引入額外的庫

Manifest 配置文件

//***
    <activity android:name=".MainActivity2">
        <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:host="cmo.sogou.translate"
                android:pathPrefix="/test"
                android:scheme="http" />
	    </activity>

//***
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章