LoginSignup
0
1

More than 1 year has passed since last update.

AndroidのDeepLinkを手軽にdebugする

Posted at

「DeepLink」
モバイル開発においてよく使う機能であり、ユーザとしても便利なものであり、そしてdebugがやりづらい。という開発においては苦しいもの。というイメージが個人的にはありました。(本番環境や開発環境でURL違うなど準備もそこそこある)
それを解決する方法を本記事では紹介します。

DeepLinkについてざっくりと

  • iOSのユニバーサルリンクと似ている
  • httpも使用可能
  • カスタムURLスキームと似ているが微妙に異なる
  • タップすると設定されたアプリが起動される
  • 特定の画面を表示させることも可能

解決したいこと

  • DeepLinkのためにサーバやドメインなどを準備したくない
  • 手早く動作確認したい

Android Studioでの設定

AndroidManifestにfilterを設定

<activity
  android:name="com.example.android"
  android:exported="true">
  <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:scheme="https"
      android:host="${serverUrl}"
      android:pathPattern="/.*/hogehoge/.*" />
  </intent-filter>
</activity>

Activityで起動時の処理を作成

override fun onCreate(savedInstanceState: Bundle?) {
  // deeplink起動時の値を取得する方法
  intent.data?.let { -> uri
    // eg.GETのクエリを取る
    val param = it.getQueryParameter("query-key")
  }
}

本記事のメインディッシュ

debugするためのコマンド

上記より抜粋

# command
$ adb shell am start -W -a android.intent.action.VIEW -d <URI> <PACKAGE>

# e.g.
$ adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.example.android

これで実行中のappよりDeepLinkした時の動作確認が可能となる。
http でも https でもいけるしURLのQueryなども設定可能。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1