亚洲乱色熟女一区二区三区丝袜,天堂√中文最新版在线,亚洲精品乱码久久久久久蜜桃图片,香蕉久久久久久av成人,欧美丰满熟妇bbb久久久

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

瀏覽器點擊鏈接打開指定APP是如何實現(xiàn)的?

admin
2025年8月5日 18:39 本文熱度 1313

什么是 URL Scheme?

android中的scheme是一種頁面內(nèi)跳轉(zhuǎn)協(xié)議,是一種非常好的實現(xiàn)機制,通過定義自己的scheme協(xié)議,可以非常方便跳轉(zhuǎn)app中的各個頁面;通過scheme協(xié)議,服務(wù)器可以定制化告訴App跳轉(zhuǎn)那個頁面,可以通過通知欄消息定制化跳轉(zhuǎn)頁面,可以通過H5頁面跳轉(zhuǎn)頁面等。


URL Scheme應(yīng)用場景:


客戶端應(yīng)用可以向操作系統(tǒng)注冊一個 URL scheme,該 scheme 用于從瀏覽器或其他應(yīng)用中啟動本應(yīng)用。通過指定的 URL 字段,可以讓應(yīng)用在被調(diào)起后直接打開某些特定頁面,比如商品詳情頁、活動詳情頁等等。也可以執(zhí)行某些指定動作,如完成支付等。也可以在應(yīng)用內(nèi)通過 html 頁來直接調(diào)用顯示 app 內(nèi)的某個頁面。綜上URL Scheme使用場景大致分以下幾種:


服務(wù)器下發(fā)跳轉(zhuǎn)路徑,客戶端根據(jù)服務(wù)器下發(fā)跳轉(zhuǎn)路徑跳轉(zhuǎn)相應(yīng)的頁面


H5頁面點擊錨點,根據(jù)錨點具體跳轉(zhuǎn)路徑APP端跳轉(zhuǎn)具體的頁面


APP端收到服務(wù)器端下發(fā)的PUSH通知欄消息,根據(jù)消息的點擊跳轉(zhuǎn)路徑跳轉(zhuǎn)相關(guān)頁面


APP根據(jù)URL跳轉(zhuǎn)到另外一個APP指定頁面


URL Scheme協(xié)議格式:

先來個完整的URL Scheme協(xié)議格式:

openapp://thisapp:8888/content?Id=10011002

通過上面的路徑 Scheme、Host、port、path、query全部包含,基本上平時使用路徑就是這樣子的。(Scheme和Host是必要的)


openapp代表該Scheme 協(xié)議名稱(相當(dāng)于http這樣的協(xié)議頭)


thisapp代表Scheme作用于哪個地址域(相當(dāng)于baidu.com這樣的域名格式,當(dāng)然,可以不需要.com這樣的后綴)


content代表Scheme指定的頁面(相當(dāng)于 baidu.com/css 這樣的路徑,然后在app內(nèi)打開相關(guān)的頁面)


Id代表傳遞的參數(shù)(相當(dāng)于 https://www.baidu.com/s?wd=12312 這樣的GET參數(shù))


8888代表port該路徑的端口號


URL Scheme如何使用:

1.在AndroidManifest.xml中對 < activity / > 標(biāo)簽 增加 < intent-filter /> 設(shè)置Scheme

<activity            android:name=".GoodsDetailActivity"            <!--Activity的名稱-->            android:theme="@style/AppTheme">             <!--Activity的主題-->            <!--要想在別的App上能成功調(diào)起App,必須添加intent過濾器-->            <intent-filter>                <!--協(xié)議部分,隨便設(shè)置-->                <data android:scheme="openapp" android:host="thisapp" android:path="/content" android:port="8888"/>                <!--下面這幾行也必須得設(shè)置-->                <category android:name="android.intent.category.DEFAULT"/>                <action android:name="android.intent.action.VIEW"/>                <category android:name="android.intent.category.BROWSABLE"/>            </intent-filter></activity>

2.JAVA獲取Scheme跳轉(zhuǎn)的參數(shù)

Uri uri = getIntent().getData();if (uri != null) {    // 完整的url信息    String url = uri.toString();    Log.e(TAG, "url: " + uri);    // scheme部分    String scheme = uri.getScheme();    Log.e(TAG, "scheme: " + scheme);    // host部分    String host = uri.getHost();    Log.e(TAG, "host: " + host);    //port部分    int port = uri.getPort();    Log.e(TAG, "host: " + port);    // 訪問路勁    String path = uri.getPath();    Log.e(TAG, "path: " + path);    List<String> pathSegments = uri.getPathSegments();    // Query部分    String query = uri.getQuery();    Log.e(TAG, "query: " + query);    //獲取指定參數(shù)值    String goodsId = uri.getQueryParameter("Id");    Log.e(TAG, "Id: " + Id);}

3.調(diào)用方式
HTML網(wǎng)頁

<a href="openapp://thisapp:8888/content?Id=10011002">打開商品詳情</a>

原生調(diào)用

  Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("xl://goods:8888/goodsDetail?goodsId=10011002"));  startActivity(intent);

4.如何判斷一個Scheme是否有效

PackageManager packageManager = getPackageManager();Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("xl://goods:8888/goodsDetail?goodsId=10011002"));List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);boolean isValid = !activities.isEmpty();if (isValid) {    startActivity(intent);}

如果手機內(nèi)沒有安裝該APP則JS跳轉(zhuǎn)至下載頁面

 <!DOCTYPE html>    <html lang="en">    <head>    <title>h5跳原生</title>    </head>    <body></body>    <script>    (function(){        var ua = navigator.userAgent.toLowerCase();        var t;        var config = {/*scheme:必須*/                scheme_IOS'openapp://',                scheme_Adr'openapp://thisapp:8888/content?Id=10011002',                download_url'http://www.baidu.com',                //下載地址                timeout600        };        function openclient() {            var startTime = Date.now();            var ifr = document.createElement('iframe');            ifr.src = ua.indexOf('os') > 0 ? config.scheme_IOS : config.scheme_Adr;            ifr.style.display = 'none';            document.body.appendChild(ifr);            var t = setTimeout(function() {                var endTime = Date.now();
                if (!startTime || endTime - startTime < config.timeout + 200) {                    window.location = config.download_url;                } else {                }            }, config.timeout);            window.onblur = function() {                clearTimeout(t);            }        }         openclient();    })()</script>    </html>

第二種

<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head><meta charset="utf-8" /><title>文檔標(biāo)題</title></head><body>    <div style="font-size: 68px;">        <a href="javascript:open_or_download_app();">打開APP</a>        <span id="device"></span>    </div>    <script type="text/javascript">    //<![CDATA[    function open_or_download_app() {        var device = document.getElementById("device");        if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {            device.innerHTML = "ios設(shè)備";            // 判斷useragent,當(dāng)前設(shè)備為ios設(shè)備            var loadDateTime = new Date();          // 設(shè)置時間閾值,在規(guī)定時間里面沒有打開對應(yīng)App的話,直接去App store進(jìn)行下載。            window.setTimeout(function() {                var timeOutDateTime = new Date();                if (timeOutDateTime - loadDateTime <2200) {                    window.location = "xxxxxxxx";  // APP下載地址                } else {                    window.close();                }            },2000);             window.location = "openapp://thisapp:8888/content?Id=10011002";  //ios端URL Schema        } else if (navigator.userAgent.match(/android/i)) {            device.innerHTML = "Android設(shè)備";            // 判斷useragent,當(dāng)前設(shè)備為Android設(shè)備            // 判斷useragent,當(dāng)前設(shè)備為ios設(shè)備            var loadDateTime = new Date();          // 設(shè)置時間閾值,在規(guī)定時間里面沒有打開對應(yīng)App的話,直接去App store進(jìn)行下載。            window.setTimeout(function() {                var timeOutDateTime = new Date();                if (timeOutDateTime - loadDateTime < 2200) {                    window.location = "xxxxxxxx";   // APP下載地址                } else {                    window.close();                }            },2000);             window.location = "openapp://thisapp:8888/content?Id=10011002";  // Android端URL Schema         }     }     //]]></script></body></html>

總結(jié):
Scheme的基本使用也就這么多了,其他的使用在以后用到的時候再做總結(jié)。


該文章在 2025/8/5 18:39:24 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved