Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
902 views
in Technique[技术] by (71.8m points)

deep linking - How to use PathPattern in order to create DeepLink Apps Android?

I have read documentation about create an deeplink and use app linking service in android studio 3.0. its pretty simple and easy to understand, but I have little bit problem when my URL has no prefix path. example :

https://example.com//amp

there is no prefix, its directly url pattern. when i use regex

^[a-z0-9]+(?:-[a-z0-9]+)*$

it doesnt works, error shown as

The URL doesnt map to any activity

when i use only star, like :

https://example.com/*/amp

its show seem error. i got stuck in this step, I've check much tutorial about deeplink, and there always use pathPrefix instead of pathPattern.

please somebody help me. thankyou so much

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's a common drawback in android deep linking that it only support * and . regex character. It's mentioned in Android docs and can be observed in source code.

From docs:

For more information on these three types of patterns, see the descriptions of PATTERN_LITERAL, PATTERN_PREFIX, and PATTERN_SIMPLE_GLOB in the PatternMatcher class.

PATTERN_SIMPLE_GLOB is for regex and it says only match

/** * Pattern type: the given pattern is interpreted with a * simple glob syntax for matching against the string it is tested against. * In this syntax, you can use the '*' character to match against zero or * more occurrences of the character immediately before. If the * character before it is '.' it will match any character. The character * '' can be used as an escape. This essentially provides only the '*' * wildcard part of a normal regexp. */

public static final int PATTERN_SIMPLE_GLOB = 2;

So only *, . and are allowed. Usage of other pattern literal +,? etc; will result in failure.

Either you can use your working option or you can use

https://example.com/./....*

....* at least 3 characters then .* mean 0 or more characters

<activity
    android:name="packagename.ActivityName" >
    <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:scheme="http"
              android:host="www.example.com"
              android:pathPattern="/./....*" />
        <!-- note that the leading "/" is required for pathPrefix-->
    </intent-filter>
</activity>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...