Slinger - deep linking library for Android

Overview

Slinger - deep linking library for Android

Build Status

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 provide deep links for quite complicated URLs.

Scheme of Slinger resolving Activities using regular expression

How do I use it?

Declare Activity in your manifest with your own IntentResolver that will handle links within particular domain.

<activity
  android:name="pl.allegro.android.slinger.SlingerActivity"
  android:excludeFromRecents="true"
  android:noHistory="true"
  android:theme="@style/android:Theme.NoDisplay">
  <meta-data
    android:name="IntentResolver"
    android:value="com.my.appp.ExampleIntentResolver"/>
    <intent-filter android:label="@string/app_name">
      <action android:name="android.intent.action.VIEW"/>
      <category android:name="android.intent.category.DEFAULT"/>
      <category android:name="android.intent.category.BROWSABLE"/>
      <data
        android:host="example.com"
        android:pathPattern="/.*"
        android:scheme="http"/>
    </intent-filter>
</activity>

IntentResolver is a class that redirects URLs to concrete Activities based on regular expressions.

@Keep
public class ExampleIntentResolver extends IntentResolver {

  private List<RedirectRule> 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<RedirectRule> 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 by default. This can be changed by overriding enrichIntent in IntentResolver

@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.

You might also like...
Very easy to use wrapper library for Android SharePreferences

Treasure English document Treasure是一个Android平台上基于SharePreferences的偏好存储库,只需要定义接口,无需编写实现,默认支持Serializable和Parcelable。运行时0反射,不仅使用方便而且性能和原生写法几乎无差别。 使用方法 1

Error handling library for Android and Java

ErrorHandler Error handling library for Android and Java Encapsulate error handling logic into objects that adhere to configurable defaults. Then pass

Small Android library to help you incorporate MVP, Passive View and Presentation Model patterns in your app
Small Android library to help you incorporate MVP, Passive View and Presentation Model patterns in your app

DroidMVP About DroidMVP is a small Android library to help you incorporate the MVP pattern along with Passive View and Presentation Model (yes, those

A simple Android utils library to write any type of data into cache files and read them later.

CacheUtilsLibrary This is a simple Android utils library to write any type of data into cache files and then read them later, using Gson to serialize

Android library that regroup bunch of dateTime utilities

DateTimeUtils This library is a package of functions that let you manipulate objects and or java date string. it combine the most common functions use

A simple and easy to use stopwatch and timer library for android

TimeIt Now with Timer support! A simple and easy to use stopwatch and timer library for android Introduction A stopwatch can be a very important widge

Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.

Trail Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platfor

UI form validation library for Android
UI form validation library for Android

Android Saripaar v2 சரிபார் - sari-paar (Tamil for "to check", "verify" or "validate") Android Saripaar is a simple, feature-rich and powerful rule-ba

Phrase is an Android string resource templating library

Phrase - Android string formatting CharSequence formatted = Phrase.from("Hi {first_name}, you are {age} years old.") .put("first_name", firstName)

Comments
  • NPE when activity is not registered in manifest

    NPE when activity is not registered in manifest

    When activity SlingesActivity redirects to is not registered in AndriudManifest slinger throws:

    java.lang.NullPointerException: Attempt to read from field 'android.content.pm.ActivityInfo android.content.pm.ResolveInfo.activityInfo' on a null object reference
                                                                       at pl.allegro.android.slinger.IntentStarter.hasDefaultHandler(IntentStarter.java:139)
    

    it should be caught and rethrown with some better explaination.

    opened by krzysiekbielicki 0
  • When App links are enabled web browser does not appear for non handled links.

    When App links are enabled web browser does not appear for non handled links.

    1. Android M + App links manually enabled for Slinger Example (example.com)
    2. adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http: //example.com/meh"
    3. Crash - no Activities can handle this.
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime: FATAL EXCEPTION: main
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime: Process: pl.allegro.android.slinger.sample, PID: 15657
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.allegro.android.slinger.sample/pl.allegro.android.slinger.example.ExampleSlingerActivity}: java.lang.IllegalArgumentException
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:  Caused by: java.lang.IllegalArgumentException
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at java.util.AbstractList.subList(AbstractList.java:736)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at pl.allegro.android.slinger.IntentStarter.getIntentList(IntentStarter.java:164)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at pl.allegro.android.slinger.IntentStarter.showChooser(IntentStarter.java:155)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at pl.allegro.android.slinger.IntentStarter.startActivity(IntentStarter.java:142)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at pl.allegro.android.slinger.SlingerActivity.excludeSlingerAndStartTargetActivity(SlingerActivity.java:37)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at pl.allegro.android.slinger.SlingerActivity.onCreate(SlingerActivity.java:27)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:6237)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148) 
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417) 
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    10-19 17:10:04.830 15657-15657/pl.allegro.android.slinger.sample E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
    
    opened by kkocel 0
Owner
Allegro Tech
Allegro Tech Open Source Projects
Allegro Tech
Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Shahid Iqbal 4 Nov 29, 2022
A robust native library loader for Android.

ReLinker A robust native library loader for Android. More information can be found in our blog post Min SDK: 9 JavaDoc Overview The Android PackageMan

Keepsafe 2.9k Dec 27, 2022
Joda-Time library with Android specialization

joda-time-android This library is a version of Joda-Time built with Android in mind. Why Joda-Time? Android has built-in date and time handling - why

Daniel Lew 2.6k Dec 9, 2022
UPnP/DLNA library for Java and Android

Cling EOL: This project is no longer actively maintained, code may be outdated. If you are interested in maintaining and developing this project, comm

4th Line 1.6k Jan 4, 2023
:iphone: [Android Library] Get device information in a super easy way.

EasyDeviceInfo Android library to get device information in a super easy way. The library is built for simplicity and approachability. It not only eli

Nishant Srivastava 1.7k Dec 22, 2022
Android library for viewing, editing and sharing in app databases.

DbInspector DbInspector provides a simple way to view the contents of the in-app database for debugging purposes. There is no need to pull the databas

Infinum 924 Jan 4, 2023
Android Market In-app Billing Library

Update In-app Billing v2 API is deprecated and will be shut down in January 2015. This library was developed for v2 a long time ago. If your app is st

Robot Media 533 Nov 25, 2022
An Android library allowing images to exhibit a parallax effect that reacts to the device's tilt

Motion An Android library allowing images to exhibit a parallax effect. By replacing static pictures and backgrounds with a fluid images that reacts t

Nathan VanBenschoten 781 Nov 11, 2022
Android library to easily serialize and cache your objects to disk using key/value pairs.

Deprecated This project is no longer maintained. No new issues or pull requests will be accepted. You can still use the source or fork the project to

Anup Cowkur 667 Dec 22, 2022
Form Validator Library for Android

Android-Validator Form Validator Library for Android [](https://flattr.com/submit/auto?user_id=throrin19&url=https://github.com/throrin19/Android-Vali

Benjamin Besse 449 Dec 17, 2022