https://github.com/allegro/slinger
Slinger - deep linking library for Android
https://github.com/allegro/slinger
android deep-links
Last synced: about 1 year ago
JSON representation
Slinger - deep linking library for Android
- Host: GitHub
- URL: https://github.com/allegro/slinger
- Owner: allegro
- Created: 2015-08-21T13:56:40.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-03-20T21:53:30.000Z (about 3 years ago)
- Last Synced: 2024-04-07T15:36:04.173Z (about 2 years ago)
- Topics: android, deep-links
- Language: Java
- Homepage:
- Size: 217 KB
- Stars: 28
- Watchers: 6
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-android-ui - https://github.com/allegro/slinger
- awesome-android-libraries - slinger - deep linking library for Android (Utility)
README
Slinger - deep linking library for Android
====================
[](https://travis-ci.org/allegro/slinger)
Slinger is a small Android library for handling custom Uri which uses regular expression to
catch and route URLs which won’t be handled by normal [intent-filter](http://developer.android.com/guide/topics/manifest/data-element.html#path) mechanism.
With slinger it’s possible to provide deep links for quite complicated URLs.

## How do I use it?
Declare Activity in your manifest with your own `IntentResolver` that will handle links within particular domain.
```xml
```
`IntentResolver` is a class that redirects URLs to concrete Activities based on regular expressions.
```java
@Keep
public class ExampleIntentResolver extends IntentResolver {
private List rules;
public ExampleIntentResolver(Activity activity) {
super(activity);
rules = asList(getRedirectRuleForAboutActivity(activity));
}
private RedirectRule getRedirectRuleForAboutActivity(Activity activity) {
return RedirectRule.builder()
.intent(new Intent(activity, MyConcreteActivityA.class))
.pattern("http://example.com/abc\\\\.html\\\\?query=a.*")
.build();
}
@NonNull @Override public Iterable getRules() {
return rules;
}
}
```
In case when no redirect rule is matched `IntentResolver` will fallback to default Intent - `Uri` with `ACTION_VIEW`.
## Customizing
### Matching Activities
In order to provide other mechanism than regular expression matching you can override `resolveIntentToSling` in `IntentResolver`
### Enriching Slinged Intents with Referrer and input URL
Slinger enriches Intents with URL and [referrer](http://developer.android.com/reference/android/app/Activity.html#getReferrer()) by default.
This can be changed by overriding `enrichIntent` in `IntentResolver`
```java
@Keep
public class ExampleIntentResolver extends IntentResolver {
@NonNull
@Override
public Intent resolveIntentToSling(@NonNull Uri originatingUri) {
// implement own intent resolving strategy here
return super.resolveIntentToSling(originatingUri);
}
@Override
public Intent enrichIntent(Activity parentActivity, Intent resolvedIntent, Uri originatingUri) {
// enrich resolved intent with custom data
return super.enrichIntent(parentActivity, resolvedIntent, originatingUri).putExtra("foo","bar");
}
}
```
## Security considerations
Slinger does not sanitize input in any way. So providing security for application is your responsibility.
## License
**slinger** is published under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).