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

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.
注意这里别写错。

 

 

 

 

 

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值