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 mechanism.
With slinger it’s possible to have deep links for quite complicated URLs.
Declare Activity in your manifest that will handle links within particular domain.
<activity
android:name=".MySlingerRoutingActivity"
android:noHistory="true">
<intent-filter android:label="@string/app_name">
<data android:host="example.com"
android:pathPattern=".*"
android:scheme="http" />
</intent-filter>
</activity>
In MySlingerRoutingActivity
provide custom IntentResolver
that redirect URLs
to concrete Activities based on regular expressions.
public class MySlingerRoutingActivity extends SlingerActivity {
...
private RedirectRule getRedirectRuleForAboutActivity() {
return RedirectRule.builder()
.intent(new Intent(context, MyConcreteActivityA.class))
.pattern("http://example.com/abc\\\\.html\\\\?query=a.*")
.build();
}
@Override protected IntentResolver getIntentResolver() {
return new IntentResolver(asList(getRedirectRuleForAboutActivity()));
}
}
In case when no redirect rule is matched Slinger will fallback to default URL handler (usually browser).
IntentResolver
can be extended and resolveIntentToSling
method can be overridden to match URLs using
other mechanism than regular expression matching.
Slinger enriches Intents with URL and referrer by default.
This can be changed by overriding enrichIntent
method in SlingerActivity
To provide different way of starting Activities just override excludeSlingerAndStartTargetActivity
method in SlingerActivity
Slinger does not sanitize input in any way. So providing security for application is your responsibility.
slinger is published under Apache License 2.0.