简体   繁体   English

深度链接时奇怪的Android Intent-Filter pathPattern问题

[英]Weird Android intent-filter pathPattern issue while deep linking

I want to create deeplinks for these two http urls 我想为这两个http网址创建深层链接

https://sample-app-123.appspot.com/backoffice/#/user_reset_password?email=abc@gmail.com https://sample-app-123.appspot.com/backoffice/#/user_create_password?email=abc@gmail.com https://sample-app-123.appspot.com/backoffice/#/user_reset_password?email=abc@gmail.com https://sample-app-123.appspot.com/backoffice/#/user_create_password?email=abc @ gmail.com

I have gone through various StackOverflow answers, none of them worked. 我经历了各种StackOverflow答案,但没有一个起作用。 I got to know PatternMatcher.PATTERN_SIMPLE_GLOB is used by Android for matching pattern instead of regex expressions. 我知道PatternMatcher.PATTERN_SIMPLE_GLOB被Android用于匹配模式而不是正则表达式。

My manifest looks like 我的清单看起来像

<activity android:name=".CreateActivity"
    android:label="Create Password"
    >
    <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"></category>
    <category android:name="android.intent.category.BROWSABLE"></category>
    <data
        android:host="sample-app-123.appspot.com"
        android:scheme="https"
        android:pathPattern=".*create_password.*"
        />
    </intent-filter>

</activity>
<activity android:name=".ResetActivity"
    android:label="Reset Password"
    >
    <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"></category>
    <category android:name="android.intent.category.BROWSABLE"></category>
    <data
        android:host="sample-app-123.appspot.com"
        android:scheme="https"
        android:pathPattern=".*reset_password.*"
        />
    </intent-filter>
</activity>

I have created several tests for checking PatternMatcher.PATTERN_SIMPLE_GLOB , All tests are PASSED, i am clueless why its not working 我创建了一些测试来检查PatternMatcher.PATTERN_SIMPLE_GLOB ,所有测试都通过了,我不知道为什么它不起作用

public void testPatternMatcher() throws Exception {
    PatternMatcher mPatternMatcher;

    mPatternMatcher = new PatternMatcher("https://sample-app-123.appspot.com/backoffice\\/#\\/user_create_password.*", PatternMatcher.PATTERN_SIMPLE_GLOB);
    assertTrue(mPatternMatcher.match("https://sample-app-123.appspot.com/backoffice/#/user_create_password?email=abc@gmail.com"));
    assertFalse(mPatternMatcher.match("https://sample-app-123.appspot.com/backoffice/#/user_reset_password?email=abc@gmail.com"));

    mPatternMatcher = new PatternMatcher(".*user_create_password.*", PatternMatcher.PATTERN_SIMPLE_GLOB);
    assertTrue(mPatternMatcher.match("https://sample-app-123.appspot.com/backoffice/#/user_create_password?email=abc@gmail.com"));
    assertFalse(mPatternMatcher.match("https://sample-app-123.appspot.com/backoffice/#/user_reset_password?email=abc@gmail.com"));

    mPatternMatcher = new PatternMatcher(".*user_reset_password.*", PatternMatcher.PATTERN_SIMPLE_GLOB);
    assertFalse(mPatternMatcher.match("/backoffice/#/user_create_password?email=abc@gmail.com"));
    assertTrue(mPatternMatcher.match("/backoffice/#/user_reset_password?email=abc@gmail.com"));
}

create_password or reset_password are not part of the uri path. create_passwordreset_password不属于uri路径。
The uri path ends just before the # character. uri路径在#字符之前结束。 This is a special character that delimits the query from the hash (or anchor). 这是一个特殊字符,用于从hash (或锚点)中分隔query

scheme: https:// 方案: https://
host: sample-app-123.appspot.com 主持人: sample-app-123.appspot.com
path: /backoffice/ 路径: /backoffice/
fragment #/user_reset_password?email=abc@gmail.com 片段#/user_reset_password?email=abc@gmail.com

You should instead use url like: 您应该改用如下网址:

https://sample-app-123.appspot.com/backoffice/user_reset_password?email=abc@gmail.com
https://sample-app-123.appspot.com/backoffice/user_create_password?email=abc@gmail.com

This will work as expected. 这将按预期工作。

scheme: https:// 方案: https://
host: sample-app-123.appspot.com 主持人: sample-app-123.appspot.com
path: /backoffice/user_create_password 路径: /backoffice/user_create_password
query: email=abc@gmail.com 查询: email=abc@gmail.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM