6

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/<this is my premalink>/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.

desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

11

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>
binarynoise
  • 364
  • 3
  • 14
Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
  • Thankyou for answering my question, but when i fill my pathpattern value with your example. /*/...* there still shown seem error. here is my sample link : https://technologue.id/kemenperin-bangun-ekosistem-digital-songsong-industri-4-0/amp/ is there any java code that i must add to make it works? thankyou – Bill Tanthowi Jauhari Sep 21 '18 at 07:33
  • you need `/.*/.../` or `/.*/amp/` – Pavneet_Singh Sep 21 '18 at 15:50
  • thank you! great to see the Android Studio Links Assistent says the pattern could be [a-z]+ xD – Micha Feb 18 '22 at 13:32
  • How do I use this for files of some extension ? Example "*.abc"? – android developer Jan 04 '23 at 07:06