LoginSignup
0
0

概要

AppLinkを奮闘して、実装したので、書き留めます。
実装仲間の助けになることを願って🙏

iOSはこちら!*アプリ側の準備もこちらの前半で説明してます。
ディープリンクの実装(ユニバーサルリンク編iOS)

環境

Angular
capacitor

androidのappLinks実装

手順

1.サイトアソシエーションファイルの作成
Android の証明書の SHA256 フィンガープリントを使用する。

keytool -list -v -keystore my-release-key.keystore

keystore-sha256-8d06695d59fbbf891f5c04c404f5e6e2.png

参照:サイトアソシエーションファイルの作成

上記でcapacitorの公式の説明が書いてあったが、私の実装では「Androidは証明書はGoogleコンソールの証明書鍵」を使用したら連携ができた。

次に、Asset Links toolを利用して、Site Associationファイルを作成する。

android-config-032c0bc4890ee44d1c7e788cd6470390.png
参照:サイトアソシエーションファイルの作成

JSON出力を .well-known配下にassetlinks.jsonにコピぺする。

// assetlinks.json
[
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
      "namespace": "android_app",
      "package_name": "com.netkosoft.beerswift",
      "sha256_cert_fingerprints": ["43:12:D4:27:D7:C4:14..."]
    }
  }
]

上記ファイルをデプロイした後に、Asset Links toolで「Test statement」を押して、成功が出れば、ほぼアプリ側と連携できている。

ここで成功となっていても、他の原因でアプリ側との連携ができな場合があります。その際は、証明書が正しいかなどを確認してください!

2.インテント・フィルタの追加
AndroidManifest.xml の 要素内に、以下を追加する。

<intent-filter android:autoVerify="true">
    <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="beerswift.app" />
</intent-filter>

完成形

<activity
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
    android:name="com.netkosoft.beerswift.MainActivity"
    android:label="@string/title_activity_main"
    android:theme="@style/AppTheme.NoActionBarLaunch"
    android:launchMode="singleTask">

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <intent-filter android:autoVerify="true">
        <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="beerswift.app" />
    </intent-filter>
</activity>

参照:インテント・フィルタの追加

エミュレータでの確認の際の注意点

リンクを直接クリックしてのテストができなかった。(ボタンとかではなく、リンク自体をクリック)
そのため、コマンドを叩き、リンクをクリックさせ、機能しているか確認した。
参考にしたページ:【Android】adbコマンドを使えるよう設定する

adbコマンドを使えるようにした後
コマンド(ターミナル)

% cd /Users/{ユーザーネーム}/Library/Android/sdk/platform-tools

デバイス上のアプリがどのようなURLパターンと関連付けられているかを確認するコマンド

% adb shell pm get-app-links {パッケージネーム}

情報が1024の場合は、証明書の確認をする。
参考:How to resolve Android get-app-links Returns State 1024?

ディープリンクチェック

% adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d “https://{ディープリンクドメイン}/{deeplink}

{deeplink}は、ディープリンクのファイルのURLを指定。

つまりポイント

途中でも書いてしまったが、証明書です。
アプリのどの環境と紐付けたいかにもよるのかもしれないです。
私は、最終的に「Androidは証明書はGoogleコンソールの証明書鍵」を使用して、成功しました。

ディープリンクのはまりどころ

はまったところ

  • 遷移元とディープリンクのドメインは同じではいけない。
  • JavaScriptで、ディープリンクを起動させることができない。

この記事が助けになり抜け出せました。。。
iOS Universal Links対応のTipsとハマりどころ

まとめ

ディープリンクは、思った以上に大変でした。
とはいえ、前駆者がいたため、何とか実装できました。
今後は、他のページにも遷移できるように、実装を応用していけるといいなと思います。

その時はこの辺が参考になるかも。
App Linksに対応してみた

0
0
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
0