H5无法调起android app 的坑之 scheme 大小写
16lz
2021-01-26
H5无法调起android app 的坑之 scheme 大小写
项目中遇到的坑,此处记录一下,也为大家提个醒。
- H5无法调起android app 的坑之 scheme 大小写
- 在manifest 文件中配置h5打开activity的scheme和host
- 在html中的简单调用
- 遇到的问题
- 解决方式
- 1 转机
- 2 解决问题
- 3 注意
1. 在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中的简单调用
<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. 解决方式
4.1 转机
震惊!我无意中看到了这样一幕,彻底让我茅塞顿开..
看到没有,震不震惊?html里明明写的是 myApp,到浏览器里却变成了 myapp,也就是说,scheme在浏览器里是不分大小写的,会统一转为小写。
4.2 解决问题
震惊!我无意中看到了这样一幕,彻底让我茅塞顿开..
于是,我在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>
4.3 注意
后来因为好奇,测试了一下,不仅仅是scheme,host 也会被转为小写,所以在manifest中配置时,scheme 和 host 都要全为小写。
更多相关文章
- Android(安卓)studio下的Android(安卓)JNI调用以及动态链接库.so
- 微信支付宝支付调用SDK
- android Activity状态以及生命周期
- android setVisibility(GONE)不及时刷新的问题
- Android中WebView加载本地Html,与JavaScript与Android方法相互传
- Android平台调用so库中函数的流程及一些坑
- Android的配置界面PreferenceActivity
- Android的反射机制Reflection
- 框架和流程——OkHttp 源码详解(一)