[筆記]讓Android上的browser用你寫的app開啟連結

真是落落長的標題,不過因為沒有要仔細討論 intent filter 還是不要用什麼『極祕!Android的 intent filter萬萬強』這類聳動的 title 比較好,免得點進來一看大失所望。
當網站上有 market://xxx.ooo 這樣的連結出現,用 Android 瀏覽器點下去,就會自動打開 market下載應用程式,相當便利。如果連結是 tel:012345678 就會叫出撥號畫面,而且號碼已經帶好了,Google Map 則是 Geo:經緯度 這種形式。
我們自己開發的 Android 程式,要怎麼支援這種功能?比如說我的網站上提供這樣的連結

tarutaru://dance

希望點下去就會帶出我們的app,出現塔魯跳舞動畫..

方法:
1. 請打開 AndroidManifest.xml
2. 找到塔魯跳舞的Activity
3. 請參考下面的寫法









這樣不管你是 tarutaru:dance 還是 tarutaru://dance 還是 tarutaru:///dance 都會叫出目標activity
如果 data 這行寫成:


這樣就只有 tarutaru://mysite/xxx 才會對應到你的跳舞Activity. 也可以利用這樣來把連結導到不同Activity。
比方說 tarutaru://dance/xxx, tarutaru://panic/ooo 就可以分別對應到不同兩個Activities。
其他更多細節就請自行參考官方文件啦 ヽ( ̄∀ ̄)ノ

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>