短信或h5页面唤起android app

android短信或h5页面唤起app

需求

  • 点击短信或h5内链接跳转:若androud手机安装了目标app则跳到该app某页面;若没安装则跳到app的html下载页

思路

  • 通过scheme机制实现页面唤起。

实现

  • android app内页面scheme配置
        <activity
            android:name="com.example.test4link2app_target.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <data
                    android:host="my.host.com"
                    android:path="/get/info"
                    android:scheme="myscheme" />

                <category android:name="android.intent.category.DEFAULT" />

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>
  • h5页面配置
<a href="myscheme://my.host.com/get/info?id=10000" >点击打开目标app</a>

Demo工程

其他

  • 这里自定义的scheme可以考虑采用http,但这样会导致在点击链接后系统弹出一个选择框,若本地安装了app则app会出现在列表,若没安装则默认器浏览器
  • android6已经支持这种无缝跳转了
发布了113 篇原创文章 · 获赞 6 · 访问量 19万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章