【问题标题】:Redirect User From Browser to My App after open a specific URL打开特定 URL 后将用户从浏览器重定向到我的应用程序
【发布时间】:2016-02-25 13:20:21
【问题描述】:

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

我在清单中添加这些代码:

<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

我的应用没有打开。

【问题讨论】:

    标签: android payment intentfilter


    【解决方案1】:

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

    很遗憾,您不能完全匹配空字符串。正如文档所述:

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

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

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

    带有数据android:pathPattern=".*" 的意图过滤器将匹配任何路径,包括空路径。

    【讨论】:

    • @esmaeil ,您是否尝试从命令行启动该应用程序?当您在命令行 shell adb shell am start -a android.intent.action.VIEW -d 'myapp://returnApp?status=1' --debug-log-resolution 中执行以下命令时,logcat 中会打印什么?
    • 您好@pepyakin,当我从外壳打开它时,它工作正常,但是什么时候!在浏览器中从网页打开它不起作用,请告诉我问题所在。
    • @rana_sadam 你能告诉我你用来从网页打开应用程序的意图过滤器、shell 命令和链接吗?
    • 我也在寻找相同的!请代码
    • 如果您已解决此问题,请分享代码。提前致谢。
    【解决方案2】:
    1. 打开 Firebase 应用
    2. 点击动态链接
    3. 在 Firebase 上创建您自己的重定向回调链接,例如 https://example.page.link/payment

    1. 在 manifest.xml 文件中设置链接,如下代码所示

    <intent-filter android:label="@string/app_name" android:autoVerify="true">
               <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                   <category android:name="android.intent.category.BROWSABLE" />
                    <data android:scheme="https"
                        android:host="example.page.link" android:path="/payment"/>
                    <data android:scheme="http"
                        android:host="example.page.link" android:path="/payment"/>
        </intent-filter>
    1. 运行您的应用
    2. 在安卓手机浏览器上查看firebase链接
    3. 没问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-18
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 2023-04-08
      • 2013-03-09
      • 1970-01-01
      相关资源
      最近更新 更多