airbnb / deeplinkdispatch Goto Github PK
View Code? Open in Web Editor NEWA simple, annotation-based library for making deep link handling better on Android
Home Page: http://nerds.airbnb.com/deeplinkdispatch/
A simple, annotation-based library for making deep link handling better on Android
Home Page: http://nerds.airbnb.com/deeplinkdispatch/
DeepLinkDispatch is not very memory efficient when it comes to matching the uris. Say that you have 20 entries, building the registry will parse 20 pattern in the constructor even if all the entries are not used. As a workaround, getParameters()
and matches()
could be merged and return a new object containing all the parsed uri details. That way there's no need to create a regex and set of parameters when building the DeepLinkEntry
. In terms of code, that's how it would look like:
DeepLinkRegistry:
public DeepLinkMatch parseUri(String uri) {
for (DeepLinkEntry entry : registry) {
final Optional<DeepLinkMatch> match = entry.matches(uri);
if (match.isPresent()) {
return match.get();
}
}
return null;
}
DeepLinkEntry:
Optional<DeepLinkMatch> matches(String inputUri) {
DeepLinkUri parsedUri = DeepLinkUri.parse(uri);
String schemeHostAndPath = schemeHostAndPath(parsedUri);
Set<String> parameters = parsePathParameters(parsedUri);
Pattern regex = Pattern.compile(schemeHostAndPath.replaceAll(PARAM_REGEX, PARAM_VALUE) + "$");
DeepLinkUri inputParsedUri = DeepLinkUri.parse(inputUri);
boolean isMatch = inputParsedUri != null && regex.matcher(schemeHostAndPath(inputParsedUri)).find();
if (isMatch) {
Iterator<String> paramsIterator = parameters.iterator();
Map<String, String> paramsMap = new ArrayMap<>(parameters.size());
Matcher matcher = regex.matcher(schemeHostAndPath(inputParsedUri));
int i = 1;
if (matcher.matches()) {
while (paramsIterator.hasNext()) {
String key = paramsIterator.next();
String value = matcher.group(i++);
if (value != null && !"".equals(value.trim())) {
paramsMap.put(key, value);
}
}
}
return Optional.of(new DeepLinkMatch(this, paramsMap));
} else {
return Optional.absent();
}
}
DeepLinkMatch:
public class DeepLinkMatch {
private final DeepLinkEntry entry;
private final Map<String, String> parameters;
public DeepLinkMatch(DeepLinkEntry entry, Map<String, String> parameters) {
this.entry = entry;
this.parameters = parameters;
}
public DeepLinkEntry getEntry() {
return entry;
}
public Map<String, String> getParameters() {
return parameters;
}
}
Do you guys agree with that and should I work on a PR? It would require a few changes in the processor.
Trying:
@DeepLink(R.string.web_frontend + "/scope/{token}")
gives:
Error:Malformed Deep Link URL 2131296410/scope/{token}
Is there a way I can use resource strings in the urls?
I've different resource strings depending on app flavors.
In a build.gradle we can have the deeplinkdepatch point to its own proguard rules like such.
android {
defaultConfig {
consumerProguardFiles 'consumer-proguard-rules.pro'
}
}
This would require turning deeplinkdepatch into an android library project. Would this be something of interest or should this remain a java module?
Modify @DeepLink
and @DeepLinks
to also require the scheme://
in the URI definition, so we can suport more than one scheme in DeepLinkActivity
.
Right now you have to extract deep link parameters from the Intent extras, which is still pretty error prone since there is no compile time validation. We could leverage our annotation processor here to generate a class that contains all the Activity's deep link parameters, say FooActivity_DeepLink
where you'd retrieve all the information from methods in this activity.
Currently I have seen that the regex (DeepLinkEntry.PARAM_VALUE) is "([a-zA-Z0-9_#!+%~,-.$]*)".
However I have url deeplinks that contains other characters, for example '&'.
https://www.mycompany.com/foo%20&%20bar
So they will not match.
The proposal is to allow the client to customize this regex. (Maybe using meta-data tag in the manifest?)
Thanks.
For example : https://et/1/#/101
@deeplink (https://et/{id}/#/{name})
I try to getString("name") --> I get null value
but in case @deeplink (https://et/{id}/{name})
I get correct value
Thank you so much :)
with a url that contains spaces for example that are replaced with "%20" doesn't get matched :
for example with a url http://www.example.com/action/search%20paris%20France%2092130"
and with an annotation on an Activity like : @DeepLinks({"http://www.example.com/action/{searchAddress}"})
no match is found and DeepLinkEntry entry = registry.parseUri(uriString);
in DeepLinkActivity always returns a null entry and so
else {
notifyListener(true, uri, "No registered entity to handle deep link: " + uri.toString());
finish();
}
is called instead.
is this not supported ?
Thanks.
As with the example here, is there a way to fetch out the "param1" value, so that I can put it in the Intent as an extra with my own key/value pair?
@DeepLink("foo://example.com/methodDeepLink/{param1}")
public static Intent intentForDeepLinkMethod(Context context) {
return new Intent(context, MainActivity.class).setAction(ACTION_DEEP_LINK_METHOD);
}
Thanks,
Jia
Currently, the static method needs to return a single Intent object
public static Intent newIntent(Context context) {
return new Intent(context, BlahActivity.class);
}
Ideally, we'd like to be able to work with something like this:
public static Intent[] newIntent(Context context) {
return new Intent[] { newIntentOne(context), newIntentTwo(context) };
}
Hello
I have a problem with my sms app that doesn't recognize custom schemes as valid urls to be clicked on.
Using this library helps with this problem or not?
Thanks
I'm having some issues implementing this in my build. I've one successful build where DeepLinkActivity was generated, but most of the time it is not getting generated.
I have a few other apt libraries in my build so I wonder if that is causing conflicts?
Is there a way I can debug why DeepLinkActivity is not getting generated?
Using a deep link with a scheme of jackson5://
will cause a compilation error
Not sure if it's a bug or on purpose but DeepLinkDispatch does not handle Uris with just the base scheme, like airbnb://
. In that case, DeepLinkUri.parse()
with return ParseResult.INVALID_HOST
. Not sure if we should handle it, any other thoughts?
Dear,
when I add
compile 'com.airbnb:deeplinkdispatch:1.1.0'
apt 'com.airbnb:deeplinkdispatch-processor:1.1.0'
to gradle file, I face this error:
Error:(42, 0) Gradle DSL method not found: 'apt()'
I use gradle:
classpath 'com.android.tools.build:gradle:1.2.3'
Please advise.
Hi,
I would like to ask you about proguard rule for annotated methods, which prepare intents.
-keepclasseswithmembers class * {
public static android.content.Intent *(android.content.Context);
}
works, but I would like to do it better using something similar to:
-keepclasseswithmembers class * {
@com.airbnb.deeplinkdispatch.DeepLink <methods>;
}
but it does not work - proguard removes unused methods.
What do I wrong?
Thank you in advance for answer and great library.
Best regards,
Jack
DLD seems to assume that all templating happens on "path parameters", and never on the "host". (i.e. airbnb://foo/{bar}
is valid, but airbnb://{bar}
is not.)
Is this expected functionality (I don't think it's documented)? If not, I can try to put up a PR for the change.
Why do we have to enter the Manifest Activity manually? Can't you just make it happen within the library thanks to Manifest merger.
Hey team. Good stuff with this library!
What would you say if I added Branch as an optional component to call the dispatch on install if the user originated from a deep link? That way, folks can choose to add in a post-install deep linking component if they so choose.
I can it to the sample project and add some simple instructions on calling the dispatch directly. Plus, with Branch, they can create hosted URLs with custom deep link paths to complete the full circle integration from link -> dispatch.
Give me 👍 to proceed and I'll make PR or let me know your thoughts.
Hi
So I tried and tested the library for my android app. Everything worked fine. Then I had to enable multi dex due to 65K limit.
Now the deeplink won't open the target activity. Instead I would only see this in the console
I/MultiDex﹕ VM with version 2.1.0 has multidex support
I/MultiDex﹕ install
I/MultiDex﹕ VM has multidex support, MultiDex support library is disabled.
As a result, the app won't open at all.
EDIT: Please see the the updated issue in comment 5
Testing the sample app and finding some of the deep link are not resolving. I believe I am using the correct adb cmds and deeplinks defined in the sample? but I'd appreciate second pair of eyes.
The following work a-ok :)
adb shell am start -W -a android.intent.action.VIEW -d "dld://example.com/deepLink" com.airbnb.deeplinkdispatch.sample
adb shell am start -W -a android.intent.action.VIEW -d "http://example.com/fooScott" com.airbnb.deeplinkdispatch.sample
However these don't resolve intent :(
adb shell am start -W -a android.intent.action.VIEW -d "dld://classDeepLink?qp=123" com.airbnb.deeplinkdispatch.sample
adb shell am start -W -a android.intent.action.VIEW -d "dtd://host/somePath/54321" com.airbnb.deeplinkdispatch.sample
adb shell am start -W -a android.intent.action.VIEW -d "dld://classDeepLink" com.airbnb.deeplinkdispatch.sample
adb shell am start -W -a android.intent.action.VIEW -d "dld://methodDeepLink/abc123" com.airbnb.deeplinkdispatch.sample
adb shell am start -W -a android.intent.action.VIEW -d "dtd://example.com/deepLink/scottid123" com.airbnb.deeplinkdispatch.sample
I then wondered if it's because I had the action wrong, but adding the defined actions doesn't seem to help either.
adb shell am start -W -a deep_link_complex -d "dtd://host/somePath/54321" com.airbnb.deeplinkdispatch.sample
adb shell am start -W -a deep_link_method -d "dld://methodDeepLink/scottsparam" com.airbnb.deeplinkdispatch.sample
To confirm this is what I'm seeing output from adb
macbook:~ user$ adb shell am start -W -a android.intent.action.VIEW -d "dld://classDeepLink?qp=123" com.airbnb.deeplinkdispatch.sample
Starting: Intent { act=android.intent.action.VIEW dat=dld://classDeepLink?qp=123 pkg=com.airbnb.deeplinkdispatch.sample }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=dld://classDeepLink?qp=123 flg=0x10000000 pkg=com.airbnb.deeplinkdispatch.sample }
Currently, all deeplink handling is done in a generated DeepLinkActivity
that you must add to your manifest. While this is a convenient mechanism for easy dropping in, it's not very extensible if you have any requirements around your deeplinking. In particular, you ultimately don't control the entry point to your app, and can't run any sort of preconditions.
Any app that has required login to proceed faces this issue. You receive a deeplink, check if the user is logged in, if yes then proceed, otherwise take them to the login screen. Unfortunately this doesn't allow for that kind of handling since there's no control over the generated activity. The dispatch gets done, regardless of the app state.
The generated DeepLinkActivity
is actually well-suited to extraction to a class. My proposal is this: generate a Dispatcher
class like the following:
public final class Dispatcher {
public static DispatchResult dispatchFrom(Activity activity) {
// Check activity != null...
// Do all the dispatch handling...
// Return the result
return new DispatchResult(isError, uri, errorMessage);
}
}
Where DispatchResult
is a simple data class representing the information you'd otherwise send to the DeepLinkReceiver
.
This would allow you to take advantage of the main benefit of the library (generated uri handling) while allowing you to keep control over entry points.
public class LaunchActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isDeepLink() && requiredConditionsAreValid() && isLoggedIn()) {
DispatchResult result = Dispatcher.dispatchFrom(this);
if (!result.isSuccessful()) {
// Do something about it
else {
// Done? Maybe? ¯\_(ツ)_/¯
return;
}
}
}
}
You could keep the currently existing implementation as well for convenience and just have it call through to the Dispatcher
. This would also make it easy to test, especially if you opted for a new instance vs. static methods (which opens up easy injection and handling via Dagger/other DI implementations).
The alternative idea would be to add some form of precondition callback that the developer could register. This isn't as ideal though since it's fairly limited.
Names are totally up for discussion by the way! Curious to hear people's thoughts on this. If it's something you'd be for, can gladly contribute a PR for this.
Hello, thank you for this library. I'd like to ask if it is possible to use it with scheme only. What I am trying to achieve is to catch everything that is myscheme:// and point it to my MainActivity. But since URL specified with annotation requires some host, it is not possible.
My question is, is there any way how to do @deeplink("myscheme://")?
Thank you
getIntent().getBooleanExtra(DeepLink.IS_DEEP_LINK, false) returns always false, even when I open app from deeplink.
My annotation looks like @DeepLink("myapp://open")
My command to open deeplink am start -W -a android.intent.action.VIEW -d "myapp://open"
I discovered an issue with the @DeepLinks
annotation in version 1.2.0. When using a single link with @DeepLink
it works fine but as soon as I use @DeepLinks
with multiple URIs it stops working and the DeepLinkLoader.java
class is not generated anymore. Also, calling ./gradlew --stop
and doing a clean build doesn't fix it.
In the following code you can see that a null uri will be passed down to notifyListener and uri.toString()
will be called on it.
public final class DeepLinkDelegate {
// code
public static DeepLinkResult dispatchFrom(Activity activity) {
if (activity == null) {
throw new NullPointerException("activity == null");
}
Intent sourceIntent = activity.getIntent();
Uri uri = sourceIntent.getData();
if (uri == null) {
return createResultAndNotify(activity, false, null, "No Uri in given activity's intent.");
}
// Code
}
private static DeepLinkResult createResultAndNotify(Context context, final boolean successful, final Uri uri, final String error) {
DeepLinkResult result = new DeepLinkResult(successful, uri, error);
notifyListener(context, !successful, uri, error);
return result;
}
private static void notifyListener(Context context, boolean isError, Uri uri, String errorMessage) {
Intent intent = new Intent();
intent.setAction(DeepLinkHandler.ACTION);
intent.putExtra(DeepLinkHandler.EXTRA_URI, uri.toString()); // <-- NPE here
intent.putExtra(DeepLinkHandler.EXTRA_SUCCESSFUL, !isError);
if (isError) {
intent.putExtra(DeepLinkHandler.EXTRA_ERROR_MESSAGE, errorMessage);
}
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
}
Hi,
I have implemented deep link dispatch, and deep links seem to be working fine. However, there are issues with Fetch as google bot for android apps. (Link: https://support.google.com/webmasters/answer/6178089?hl=en)
Specifically, it says that the URI is unsupported. Same Uri is working perfectly fine, otherwise.
Do you think it has something to do with this library?
The files generated by apt have the file names that are hard coded like following.
As a result, the library can only apply into the project owning only one module app. Otherwise, if applied into one main app and other depend library module, there would be more than one generated files with same names. And that would lead to dex error.
Would you please upgrade the current implementation to support multi-modules project?
Right now if you use something like @DeepLinks({"example.com/deepLink/{id}", "example.com/anotherDeepLink"})
, you can determine which link was used by the presence of id
. But if you did something like @DeepLinks({"example.com/deepLink", "example.com/anotherDeepLink"})
, you'd have no mechanism to determine which path was used to get here.
Its is possible to do the boostrap or start up work such as app initialization and authentication in a central location (in the dispatcher) so that the activity which has the deep link does not have to take care of this.
In the Generated DeepLinkActivity's class is it possible to handle parent Activity ?
Something like that :
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
Class<?> currentClass = entry.getActivityClass();
while (hasParentActivity(currentClass)){
stackBuilder.addParentStack(currentClass);
currentClass = getParentActivity(currentClass);
}
stackBuilder.addNextIntent(intent);
startActivities(stackBuilder.getIntents());
if it's possible there is still a problem with the required parameter (intent extra) of the parent stack.
We should probably send the same extra parameter to the back stack ?
FYI from now i use NavUtils
in every Deeplink activity
Android documentation :
http://developer.android.com/training/implementing-navigation/temporal.html#SynthesizeBackStack
We could move the regex code that extracts parameters from the URI into compile time by baking that into the processor
Hi all
I was wondering if you have any updates on release plans? I love the library, but am having trouble with user authentication using the DeepLinkActivity. Essentially, I want to be able to check if user is logged in before redirecting them to the relevant activity. I know that this was implemented in #87 and I see other places where you guys have spoken about version 1.6.0 and 2.0.0-SNAPSHOT, however when I try and update my build.gradle to use these version numbers it tells me they cannot be found. Am I missing something, or are they not yet available in Maven central? If you could let me know how to deal with this that would be great!
In a textview I have some links which should when clicked tries to open a deeplink and this is handled by deeplinkdispatch and it works as expected. But when app is launched from deeplink the links which were in the textview doesn't work anymore.
What can I do to resolve this issue.
it gives following errors
I/Timeline: Timeline: Activity_launch_request id:com.example time:141468728
I/Timeline: Timeline: Activity_launch_request id:com.example time:141468741
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2e1b4b34 time:141468837
I/Timeline: Activity_idle id: android.os.BinderProxy@31294bf4 time:141468837
Thanks,
hi,
I want to exclude some url path to prevent it open the apps because the content is not available for android app. below is my example url and action:
URL | Action |
---|---|
http://www.example.com/ | open app |
http://www.example.com/path/to/content | open app |
http://www.example.com/pathto/content | open app |
http://www.example.com/pathtocontent | open app |
http://www.example.com/help | do not open app |
http://www.example.com/contactus | do not open app |
how can i achieve this using deeplinkdispatch?
I tried airbnb android app it can open app with below url:
https://www.airbnb.com.sg/
https://www.airbnb.com.sg/rooms/4516626
https://www.airbnb.com.sg/s/Seoul--South-Korea?source=ds
but not open:
https://www.airbnb.com.sg/getaways/Singapore?destination=Kuala-Lumpur
https://www.airbnb.com.sg/help
I am trying to use the 2.0.1 release of the library and want to use the @DeepLinkHandler class annotation. However, when I try and use the DeepLinkDelegate.dispatchFrom(this) method, Android Studio cannot find the DeepLinkDelegate class. My build.gradle class includes the following:
buildscript {
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'android-apt'
dependencies {
compile 'com.airbnb:deeplinkdispatch:2.0.1'
apt 'com.airbnb:deeplinkdispatch-processor:2.0.1'
}
In my activity I have the following:
@DeepLinkHandler
public class MyDeepLinkActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Some stuff
DeepLinkDelegate.dispatchFrom(this);
finish();
}
}
Any ideas why this does not work, are there any known issues with the processor library? Or is it likely I am doing something wrong? Any help would be gratefully received .
I have registered an Activity with e.g. @DeepLink("example://www.example.com/deepLink")
and specified the custom scheme example
in com.airbnb.deeplinkdispatch.DeepLinkActivity
within AndroidManifest.xml
. This works fine but
when I use a DeepLink with an unknown pathPrefix which is not registered e.g. example://www.example.com/someOtherLink
with
adb shell am start -W -a android.intent.action.VIEW -d "example://www.example.com/someOtherLink" com.example.android
the airbnb app opens.
I think the problem is that an implicit intent is broadcasted in that case, since this DeepLinkEntry
can't be found in the DeepLinkRegistry
, and the airbnb app is handling the error case within DeepLinkReceiver
, which launches airbnb's main activity.
In my opinion this test should pass:
@Test public void multiplePathParams() {
DeepLinkEntry entry = deepLinkEntry("airbnb://foos/{foo}");
Map<String, String> parameters = entry.getParameters("airbnb://foos/baz/qux");
assertThat(parameters)
.isEmpty();
}
but it's not. It finds the parameter foo
with the value baz/qux
.
The funny thing is that I can't repro with airbnb://{foo}
and "airbnb://baz/qux"
.
missing DeepLinkActivity in the sample project
Library works fine with multiply params in URI?
example://example.com/deepLink?param1=123¶m2=456¶m3=789
?
Right now I can get only first parameter.
Best regards,
Jack
Right now the only way to take advantage of the Callbacks is to implement the interface in your Application. Consider instead using an Intent with a specific signature that could be implemented in a Broadcast Receiver.
I was about to use your library in my project, but it didn't recognize my url. As was found out, the regexp for parameters is too restrictive, as it forbids _ and - symbols.
My target url was like this:
someschema://somepath/an-identifier-with-dashes
Please, add this functionality.
If DeepLinkActivity
receives an intent that was started with startActivityForResult
there is currently no way to return a result to the Activity that sent the intent.
In the app I work on, we use capital letters in the package names, and DeeplinkDispatch incorrectly thinks that the package is a class, and that the actual activity is a nested class.
So, it generates DeepLinkLoader with "import com.example.Package"
and in the load() method:
new DeepLinkEntry("deeplink://path1", DeepLinkEntry.Type.CLASS, Package.Activity.class, null)
which fails to compile.
If I change that package name to small caps, then I can successfully compile the app, and the deeplinks work as well.
Could you please change the code to not automatically consider packages with capital letters as classes?
I believe the relevant code is in: ClassName.bestGuess() method, which is actually from squareup/javapoet
I'm trying the sample app with snapshot v2.0.0 of the library. Whenever I run the sample app through deeplink, it always crash. I think it's because the generated DeepLinkActivity
class didn't call finish()
. Here's the stack trace:
05-22 10:38:23.298 5482-5482/com.airbnb.deeplinkdispatch.sample W/Activity: An activity without a UI must call finish() before onResume() completes
05-22 10:38:23.299 5482-5482/com.airbnb.deeplinkdispatch.sample D/AndroidRuntime: Shutting down VM
05-22 10:38:23.300 5482-5482/com.airbnb.deeplinkdispatch.sample E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.airbnb.deeplinkdispatch.sample, PID: 5482
java.lang.RuntimeException: Unable to resume activity {com.airbnb.deeplinkdispatch.sample/com.airbnb.deeplinkdispatch.DeepLinkActivity}: java.lang.IllegalStateException: Activity {com.airbnb.deeplinkdispatch.sample/com.airbnb.deeplinkdispatch.DeepLinkActivity} did not call finish() prior to onResume() completing
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: Activity {com.airbnb.deeplinkdispatch.sample/com.airbnb.deeplinkdispatch.DeepLinkActivity} did not call finish() prior to onResume() completing
at android.app.Activity.performResume(Activity.java:6339)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Adding finish()
statement in its onCreateMethod
did the work.
Also, when will the new version be available in the JCenter repository? I can't wait to use it in my production app. 😄
We have kind of a weird use case here - an app with three flavors and - of course - several activities, while one of the activity should deal with a certain set of URLs in one flavor and with another set of URLs in another. These URLs only differ in scheme and we already separated that out in the flavor's distinct manifests, i.e. we have DeepLinkActivity
configured like this
<data android:scheme="ourscheme1" />
<data android:scheme="ourscheme2" />
While this should work in general (because each flavor gets its own manifest and will therefor only react on URLs of its very scheme), its still a bit ugly to have to define all possible flavor combinations on the specific activity, i.e.
@DeepLink({"ourscheme1://some/path", "ourscheme2://some/path})
public class SomeActivity extends Activity { ... }
Is there any way around this? Would it be possible to just define the path, without the scheme?
In our project we have multiple test environments (to support our myriad and varied testing requirements) together with our production environment.
The current @deeplink annotation requires us to add a URL for every single environment:
@deeplink({
“https://prod_env/showDetail/detail.html”,
“https://test_env1/showDetail/detail.html”,
“https://test_env2/showDetail/detail.html”,
“https://test_env3/showDetail/detail.html”,
“https://test_env4/mock1/showDetail/detail.html”,
“https://test_env5/mock2/showDetail/detail.html”})
public class MyShowDetailActivity ….
This results in all our test environment annotations appearing in production code! It’s unwieldy and we have sometimes introduced new test environments, which would require code change on every activity that support deep linking to add the new environment.
We acknowledge that the intent filters within AndroidManifest.xml also need to be wordy (one entry per test env), but are pretty much taken care of by having separate manifests: debug/AndroidManifest.xml (many intent filter entries - one for each env) and release/AndroidManifest.xml (only one intent filter entry for the prod env).
Unfortunately this @deeplink java annotation can’t be as easily handled. We could try subclassing and annotate the debug subclass of MyShowDetailActivity for the debug build variant but that’s rather messy, just to get around the DeepLink annotation restriction.
Instead, if there was a variant of @deeplink that matched without hostname and scheme, that would allow us to do something simple and elegant such as:
@deeplink("/showDetail/detail.html”) // support all environments in a single hit and rely on intent filters to ensure the hostname or url prefix is correct
public class MyShowDetailActivity ….
So is it possible to enhance this library to handle this partial deep link match requirement?
I have a case with this url : "http://www.example.com/#/{query}" but its not matched, i looked at the code and it's because encodedPath() in DeepLinkUri that looks for queries after ? or # .
int pathEnd = delimiterOffset(url, pathStart, url.length(), "?#");
Here's a failing test case for it :
@Test public void urlWithHash() {
DeepLinkEntry entry = deepLinkEntry("http://example.com/{any}/{nb}");
//or deepLinkEntry("http://example.com/#/{nb}");
Map<String, String> parameters = entry.getParameters("http://example.com/#/2");
assertThat(parameters.get("nb")).isEqualTo("2");
}
is there a way to have an escape character or something for such a case ?
Thank you.
I have a 1 activity project, with Android Annotations (using @EActivity to refer to the activity layout) and I am using DeeplinkDispatch on top of it
Seems like both annotations library don't go so well. If I remove either package, the app runs, but not with both
package com.example.android.deeplinktest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.airbnb.deeplinkdispatch.DeepLink;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
@EActivity(R.layout.activity_main)
@DeepLink("foo://deepLink/{id}")
public class MainActivity extends AppCompatActivity {
/* @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}*/
@AfterViews
public void init(){
if (getIntent().getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {
Bundle parameters = getIntent().getExtras();
String idString = parameters.getString("id");
((TextView)findViewById(R.id.tv)).setText(idString);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.deeplinktest" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity_"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.airbnb.deeplinkdispatch.DeepLinkActivity"
android:theme="@android:style/Theme.NoDisplay">
<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="foo" />
</intent-filter>
</activity>
</application>
</manifest>
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.android.deeplinktest"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName "com.example.android.deeplinktest"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.airbnb:deeplinkdispatch:1.3.0'
apt 'com.airbnb:deeplinkdispatch-processor:1.3.0'
apt "org.androidannotations:androidannotations:3.2"
compile 'org.androidannotations:androidannotations-api:3.2'
}
Information:Gradle tasks [clean, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72221Library
:app:prepareComAndroidSupportSupportV42221Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava
Note: Resolve log file to /Users/somghosh/Programming/DeepLinkTest/app/build/generated/source/apt/androidannotations.log
Note: Initialize AndroidAnnotations 3.2 with options {androidManifestFile=/Users/somghosh/Programming/DeepLinkTest/app/build/intermediates/manifests/full/debug/AndroidManifest.xml, resourcePackageName=com.example.android.deeplinktest}
Note: Start processing for 2 annotations on 4 elements
Note: AndroidManifest.xml file found with specified path: /Users/somghosh/Programming/DeepLinkTest/app/build/intermediates/manifests/full/debug/AndroidManifest.xml
Warning:A class activity declared in the AndroidManifest.xml cannot be found in the compile path: [com.airbnb.deeplinkdispatch.DeepLinkActivity]
Note: AndroidManifest.xml found: AndroidManifest [applicationPackage=com.example.android.deeplinktest, componentQualifiedNames=[com.example.android.deeplinktest.MainActivity_], permissionQualifiedNames=[], applicationClassName=null, libraryProject=false, debugabble=false, minSdkVersion=17, maxSdkVersion=-1, targetSdkVersion=22]
Note: Found project R class: com.example.android.deeplinktest.R
Note: Found Android class: android.R
Note: Validating elements
Note: Validating with EActivityHandler: [com.example.android.deeplinktest.MainActivity]
Note: Validating with AfterViewsHandler: [init()]
Note: Processing root elements
Note: Processing root elements EActivityHandler: [com.example.android.deeplinktest.MainActivity]
Note: Processing enclosed elements
Note: Number of files generated by AndroidAnnotations: 1
Note: Writting following API classes in project: []
Note: Generating class: com.example.android.deeplinktest.MainActivity_
Note: Time measurements: [Whole Processing = 259 ms], [Extract Manifest = 178 ms], [Process Annotations = 32 ms], [Generate Sources = 18 ms], [Find R Classes = 14 ms], [Extract Annotations = 4 ms], [Validate Annotations = 4 ms],
Note: Finish processing
Error:Error creating file
Note: Start processing for 0 annotations on 3 elements
Note: Time measurements: [Whole Processing = 0 ms],
Note: Finish processing
Note: Start processing for 0 annotations on 0 elements
Note: Time measurements: [Whole Processing = 1 ms],
Note: Finish processing
1 warning
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.