網頁打開App小記

https://developer.chrome.com/multidevice/android/intents android官網介紹

最近由于購物類某多多很火 分享拼單 點擊網頁打開app需求也越來越多 今天記錄一下此功能開發

功能描述 通過網頁打開app/下載app

應用場景 某博 某東 某貓 某多多 某寶 都有這樣的功能

Android客戶端 實現方式 URI schame + Android Intent

URI scheme 是一種頁面跳轉協議

            android:screenOrientation="portrait"
            android:configChanges="orientation|keyboardHidden|screenSize">
            <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="test" android:host="nade" android:pathPrefix="/openapp"/>
            </intent-filter>
        </activity>```



URI scheme協議格式由scheme、host、port、path和query組成 具體舉例如下 
h5網頁端的連接  
openUrl = "test://nade/openapp"

這邊要注意的時候 意圖過濾器 
<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="test" android:host="nade" android:pathPrefix="/openapp"/>
            </intent-filter>
<intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

這兩個一定要分開寫 如果寫在一起 安裝會失敗 好了 簡單著說么多 

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容