项目中遇到的坑,此处记录一下,也为大家提个醒。
在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