Android業務元件化之URL Scheme使用

2021-07-29 03:16:09 字數 1673 閱讀 5413

先來個完整的url scheme協議格式:

xl://goods:8888/goodsdetail?goodsid=10011002
通過上面的路徑 scheme、host、port、path、query全部包含,基本上平時使用路徑就是這樣子的。

1.)在androidmanifest.xml中對標籤增加設定scheme

<

activity

android:name

=".goodsdetailactivity"

android:theme

>

<

intent-filter

>

<

data

android:scheme

="xl"

android:host

="goods"

android:path

="/goodsdetail"

android:port

="8888"

/>

<

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.)獲取scheme跳轉的引數

uri uri =getintent().getdata();

if (uri != null

)

3.)呼叫方式

網頁上

<

a href

="xl://goods:8888/goodsdetail?goodsid=10011002"

>開啟商品詳情

a>

原生呼叫

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

activities = packagemanager.queryintentactivities(intent, 0);

boolean isvalid =!activities.isempty();

if(isvalid)

scheme的基本使用也就這麼多了,其他的使用在以後用到的時候再做總結。

Android業務元件化之URL Scheme使用

先來個完整的url scheme協議格式 xl goods 8888 goodsdetail?goodsid 10011002通過上面的路徑 scheme host port path query全部包含,基本上平時使用路徑就是這樣子的。1.在androidmanifest.xml中對標籤增加設定s...

Android業務元件化之URL Scheme使用

先來個完整的url scheme協議格式 xl goods 8888 goodsdetail?goodsid 10011002 通過上面的路徑 scheme host port path query全部包含,基本上平時使用路徑就是這樣子的。1.在androidmanifest.xml中對標籤增加設定...

android架構學習之元件化

新公司的專案採用了元件化,此前對元件化有過一些研究,但是相關的經驗並不多,正好新的專案有實際運用,在此記錄下元件化的學習與實踐之路。網上元件化的文章很多,本人學習組建化的過程也借鑑了網上先輩們的文章。但大多數文章都從底層的細枝末節開始講述,由下而上給人一種這門技術 博大精深 望而生畏的感覺。而我寫這...