您的位置:首页 > 移动开发

qq. 微信分享出去的页面。如何唤起app,调到指定的页面

2017-04-14 17:34 696 查看
URL Scheme是iOS,Android平台都支持,只需要原生APP开发时注册scheme,
那么用户点击到此类链接时,会自动唤醒APP,借助于URL Router机制,则还可以跳转至指定页面。

步骤:
(1)h5页面跳转的页面格式写成这样。例如 跳转页面格式为app://abc这种格式。如果需要传参数,在后面加上(?键=值)
<a class="btn_hy" id="openApp">我要分享出去</a>

<script type="text/javascript">
document.getElementById('openApp').onclick = function(){
window.location.href = "app://abc";
window.setTimeout(function(){
window.location.href = " http://xxx/mobile/xxxx.apk ";//打开app下载地址,由app同事提供
},2000)
};
</script>
(2)android端。需要在AndroidManifest.xml中。给需要打开的指定页面的activity添加intent-filter
代码如下:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="abc"
android:scheme="app" >
</data>
</intent-filter>

完整示例子:
<activity
android:name="com.example.app.ui.WebViewActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustPan" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="abc"
android:scheme="app" >
</data>
</intent-filter>
</activity>

app://abc
这里的sheme是上面上面h5写的跳转的地址,对应的app

这里的host是上面h5写的跳转地址,对应的abc.
注意这里别写错。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐