我编写了一个应用程序,用户点击购买按钮后他/她重定向到互联网浏览器(例如:chrome),付款后我希望他回到我的应用程序(我的活动),所以我发现我应该使用意图过滤器,但是这对我不起作用!
我在清单中添加这些代码:
<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="returnApp" android:scheme="myapp"></data>
</intent-filter>
当我打开这样的网址时:
myapp://returnApp?status=1
我的应用程序打不开。
尝试像这样打开它myapp://returnApp/?status=1
(添加尾部斜杠字符)。
发生这种情况是因为path http://developer.android.com/guide/topics/manifest/data-element.html#path参数定义为默认值/
.
不幸的是,您无法完全匹配空字符串。正如文档所述:
URI 的路径部分,必须以 / 开头。
如果您确实需要使用确切的网址启动应用程序myapp://returnApp?status=1
你可以加android:pathPattern=".*"
数据子句的参数,例如
<intent-filter>
...
<data android:host="returnApp" android:scheme="myapp" android:pathPattern=".*"></data>
</intent-filter>
带数据的意图过滤器android:pathPattern=".*"
将匹配任何路径,包括空路径。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)