introduction to DeepLinkDispatch

introduction to DeepLinkDispatch

introduction to DeepLinkDispatch

6dd0483f1353a4a359e92633cfd65c64?s=128

Daichi Furiya (Wasabeef)

July 14, 2015
Tweet

Transcript

  1. DeepLinkDispatch potatotips #19 Wasabeef

  2. About Me wasabeef CyberAgent, Inc.

  3. DeepLinkDispatch

  4. Airbnb, Inc.

  5. DeepLinkDispatch • Simple • Annotation-based API • and Simple

  6. Usage

  7. Gradle buildscript { dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' } } apply

    plugin: 'com.neenbedankt.android-apt' dependencies { compile 'com.airbnb:deeplinkdispatch:1.2.+' apt 'com.airbnb:deeplinkdispatch-processor:1.2.+' }
  8. AndroidManifest <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:host=“wasabeef.jp” android:scheme=“http” /> <data android:host=“*” android:scheme=“wasabeef” /> </intent-filter> </activity>
  9. Activity @DeepLinks({ “http://wasabeef.jp/deepLink/{id}”, “wasabeef://deepLink/{id}”, “wasabeef://anotherDeepLink” }) public class MainActivity extends

    Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getIntent().getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) { Bundle parameters = getIntent().getExtras(); String id = parameters.getString(id); // Do something with the ID... } ... } }
  10. Method @DeepLink(“wasabeef://methodDeepLink/{param}”) public static Intent intentForDeepLinkMethod(Context context) { return new

    Intent(context, MainActivity.class) .setAction(ACTION_DEEP_LINK_METHOD); }
  11. Callbacks public class SampleApplication extends Application implements DeepLinkCallback { private

    static final String TAG = DeepLinkDispatch; @Override public void onSuccess(String uri) { Log.i(“TAG, Successful deep link:” + uri.toString()); } @Override public void onError(DeepLinkError error) { Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName()); ComponentName componentName = intent.getComponent(); Intent mainIntent = IntentCompat.makeRestartActivityTask(componentName); startActivity(mainIntent); } }
  12. Test adb shell am start -W -a android.intent.action.VIEW \ -d

    "wasabeef://deepLink/deepLink"
  13. Thanks.