H5无法调起android app 的坑之 scheme 大小写

项目中遇到的坑,此处记录一下,也为大家提个醒。

在manifest 文件中配置h5打开activity的scheme和host
<activity
    android:name=".MainActivity"
    android:exported="true"
    android:screenOrientation="portrait"
    android:theme="@style/AppThemeNoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data
                    android:host="host"
                    android:scheme="myApp" />  <!--此处有坑,勿效仿,请阅读下文-->
        </intent-filter>
        </activity>
2. 在html中的简单调用
<!Doctype html>
<html>
    <head>
        <meta http-equiv=Content-Type content="text/html;charset=utf-8">
        <title> my test </title>
    </head>
    <body>
        <a href="myApp://main">click me to jumpping to the main page </a>
    </body>
</html>

此处h5 的调用方式确认无误,可参考。

3. 遇到的问题
html无论如何也调不起app,排查了各种原因,仔细核对了 scheme 和 host 都和h5 
的一样,却就是调不起来。
4.解决问题

震惊!我无意中看到了这样一幕,彻底让我茅塞顿开…
于是,我在android的manifest中配置filter时,把scheme改为小写,测试之后欣然发现 bug解了,app调起来了~

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data
        android:host="host"
        android:scheme="myapp" />  <!--此处需要用全小写-->
</intent-filter>

后来因为好奇,测试了一下,不仅仅是scheme,host 也会被转为小写,所以在manifest中配置时,scheme 和 host 都要全为小写。

原文链接:https://blog.csdn.net/sinat_15417921/article/details/74188480?utm_source=blogxgwz0

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值