Giter Club home page Giter Club logo

android-urlschemeinterceptor's Introduction

Android-UrlScheme Interceptor

Test it

What's gonna happen?
✘ App not installed → Redirect to Play Store
✔ App installed → Start the application or the interceptor

Click here to trigger the url scheme!

Integration

In your build.gradle file:

dependencies {
    compile 'fr.smarquis.usi:usi:1.0.0'
}

In your Application class:

public class YourApplication extends Application {

    @Override public void onCreate() {
        super.onCreate();
        Usi.intercept(this);
    }

}

If you want to intercept a custom scheme, simply override the usi_scheme string resource:

<resources>
    <string name="usi_scheme">your-custom-scheme</string>
</resources>

Or more complex, add a new IntentFilter to the InterceptorActivity:

<activity android:name="fr.smarquis.usi.InterceptorActivity">
    <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:host="your.project.com" android:scheme="http" />
    </intent-filter>
</activity>

That's it! UrlSchemeInterceptor will automatically intercept the corresponding scheme.

Manual trigger

This demo application can be launched without any modification.
Use this adb command to trigger the default url scheme with some parameters:

adb shell am start \
    -a android.intent.action.VIEW \
    -d 'usi://example.com:8042/over/there/index.html?query=something#refresh' \
    --es extra-string abc \
    --ez extra-boolean true \
    --ei extra-int 123 \
    --el extra-long 123456 \
    --ef extra-float 123.456 \
    --eu extra-uri http://www.google.com \
    --esa extra-stringArray a,b,c

Chrome Intents

The default Chrome implementation is done through intents.
Simply wrap the following intent into an <a href="..."> tag.

intent://example.com:8042/over/there/index.html?query=something#refresh#Intent;scheme=usi;package=fr.smarquis.usi.sample;action=android.intent.action.VIEW;S.string=abc;B.boolean=true;i.int=123;l.long=123456;f.float=123.456;end

The package=x.y.z; is mandatory to prompt the user to install the app if it is not already on the device.

android-urlschemeinterceptor's People

Contributors

simonmarquis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.