日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android URL Scheme

發布時間:2023/12/14 Android 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android URL Scheme 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言:

我們在使用微信的過程中,經??梢酝ㄟ^別人分享的鏈接,直接跳轉到一些APP內部。比如京東、網易云音樂,我們通過在這兩個APP內部分享鏈接到微信,微信中點擊鏈接進入微信瀏覽器打開分享的頁面,可以在頁面中看到直接打開的按鈕,點擊直接打開就進入了該APP的對應的頁面。實際上就是從微信瀏覽器中的一個頁面跳轉到APP指定的頁面。這一種效果就是通過URL Scheme來實現的。




URL Scheme

URL Scheme是一種頁面內跳轉協議,通過定義自己的URL Scheme協議,可以
從一個APP中打開另外一個APP指定的頁面,也可以從H5頁面中跳轉到APP指定的頁面(實際上就是從一個瀏覽器中的一個頁面跳轉到APP指定頁面)。

URL Scheme協議格式:

一個完整的完整的URL Scheme協議格式由scheme、host、port、path和query組成,其結構如下所示:

<scheme>://<host>:<port>/<path>?<query>

scheme可以是常見的協議名 (http、file等)也可以是自定義的協議名(自定義一個字符串即可),一般打開一個APP,大多使用自定義的協議名。

如下就是一個自定義的URL
caishilive://caishi:8080/loadtooldetail?tool_id=100
caishilive:即Scheme 該Scheme協議名稱
caishi:即Host,代表Scheme作用于哪個地址域
8080:即port,代表端口號
loadtooldetail:即path,代表打開的頁面
tool_id:即query,代表傳遞的參數

URL Scheme使用
URL Scheme的使用要先在AndroidManifest.xml中配置能接受Scheme方式啟動的activity;

<activity android:name=".ui.tool.LoadToolDetailActivity"android:screenOrientation="portrait"><!--要想在別的App上能成功調起App,必須添加intent過濾器--><intent-filter><!--協議部分,隨便設置--><data android:host="caishi"android:path="/loadtooldetail"android:port="8080"android:scheme="caishilive"/><!--下面這幾行也必須得設置--><category android:name="android.intent.category.DEFAULT"/><action android:name="android.intent.action.VIEW"/><category android:name="android.intent.category.BROWSABLE"/></intent-filter></activity>

獲取Scheme跳轉的參數

Intent intent = getIntent();String scheme = intent.getScheme();String dataString = intent.getDataString();Uri uri = intent.getData();if (uri != null) {//完整的url信息String url = uri.toString();//scheme部分String schemes = uri.getScheme();//host部分String host = uri.getHost();//port部分int port = uri.getPort();//訪問路徑String path = uri.getPath();//編碼路徑String path1 = uri.getEncodedPath();//query部分String queryString = uri.getQuery();//獲取參數值String systemInfo = uri.getQueryParameter("tool_id");}

調用方式:

(1)網頁調用

<a href="caishilive://caishi:8080/loadtooldetail?tool_id=100">打開APP工具詳情頁</a>

(2)APP上調用

Intent action = new Intent(Intent.ACTION_VIEW);StringBuilder builder = new StringBuilder();builder.append("caishilive://caishi:8080/loadtooldetail?tool_id=100");action.setData(Uri.parse(builder.toString()));startActivity(action);

當然跳轉前要判斷一下該URL Scheme是否有效

private boolean schemeValid() {PackageManager manager = mContext.getPackageManager();Intent action = new Intent(Intent.ACTION_VIEW);action.setData(Uri.parse("caishilive://caishi:8080/loadtooldetail?tool_id=100"));List list = manager.queryIntentActivities(action, PackageManager.GET_RESOLVED_FILTER);return list != null && list.size() > 0;}

以上就是URL Scheme的使用

總結

以上是生活随笔為你收集整理的Android URL Scheme的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。