打开特定的URL后,将用户从浏览器重定向到我的应用程序 [英] Redirect User From Browser to My App after open a specific URL

查看:96
本文介绍了打开特定的URL后,将用户从浏览器重定向到我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个应用程序,用户单击购买"按钮后,他/她重定向到Internet浏览器(例如chrome),付款后我希望他回到我的应用程序(我的活动),所以我发现我应该使用Intent -过滤器,但对我不起作用!

I wrote an application that user after click on buy Button He/She redirect to Internet Browser (e.g: chrome) and after payment I want he come back to my App (my activity) so I found out that I should use Intent-Filter but It doesn't work for me!

我将这些代码添加到清单中:

I add these codes in manifest:

<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>

当我打开这样的网址时:

And when I open a url like this:

myapp://returnApp?status = 1

myapp://returnApp?status=1

我的应用程序无法打开.

my app doesn't open.

推荐答案

尝试像myapp://returnApp/?status=1一样打开它(添加斜杠字符). 发生这种情况是因为 path 参数定义为默认值/.

Try to open it like myapp://returnApp/?status=1 (add trailing slash character). This is happens because path parameter is defined with default value of /.

不幸的是,您不能完全匹配空字符串.如文档所述:

Unfortunately, you can't match exactly for empty string. As documentation states:

URI的路径部分,必须以/开头.

The path part of a URI which must begin with a /.

如果您确实需要使用完全相同的网址myapp://returnApp?status=1启动应用程序,则可以将android:pathPattern=".*"参数添加到数据子句中,例如

If you are really need to start app with exactly url myapp://returnApp?status=1 you can add android:pathPattern=".*" parameter to your data clause like

<intent-filter>
    ...
    <data android:host="returnApp" android:scheme="myapp" android:pathPattern=".*"></data>
</intent-filter>

数据为android:pathPattern=".*"的意图过滤器将匹配包括空路径在内的任何路径.

Intent filter with data android:pathPattern=".*" will match for any paths including empty one.

这篇关于打开特定的URL后,将用户从浏览器重定向到我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆