メインコンテンツまでスキップ

Android App Links

Android App Linksは、Androidが標準機能として提供しているディープリンクです。

Android App Linksの概要や設定方法については、以下を参照してください。

環境ごとの設定

このアプリでは、用途に応じたいくつかの環境を用意しています。

Android App Linksを環境ごとに作成するためには、以下の2つの方法があります。

  • 環境ごとに異なるドメインを使用する
  • 環境ごとに異なるパスを使用する

このアプリでは、1つのドメインで環境ごとに異なるパスを使用する方法を採用します。

assetlinks.jsonに、環境ごとのアプリケーションIDと署名証明書のSHA256フィンガープリントを設定します。

assetlinks.jsonの例
[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "jp.fintan.mobile.SantokuApp.stg",
"sha256_cert_fingerprints": ["2A:B5:1E:6C:D8:8A:4E:B3:4C:8C:A8:7C:37:8D:56:9E:29:23:7D:AB:E1:11:C6:BE:13:58:98:55:05:F8:20:D2"]
}
},
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "jp.fintan.mobile.SantokuApp.dev",
"sha256_cert_fingerprints": ["01:AD:D7:52:B3:D1:EE:C8:E2:79:DD:C4:0D:27:DA:14:FF:D8:AF:F0:32:0A:94:05:8F:7C:E6:C9:A7:85:B7:16"]
}
},
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "jp.fintan.mobile.SantokuApp.local",
"sha256_cert_fingerprints": ["FA:C6:17:45:DC:09:03:78:6F:B9:ED:E6:2A:96:2B:39:9F:73:48:F0:BB:6F:89:9B:83:32:66:75:91:03:3B:9C"]
}
}
]
注記

このアプリでは、Androidのprod環境をまだ配布していないため、署名証明書のSHA256フィンガープリントを作成していません。

そのため、assetlinks.jsonにはprod環境の設定がありません。

app.config.[環境名].jsintentFiltersに、Android App Linksとして登録するパスなどを設定します。パスのプレフィックスに環境名を設定することで、Android App LinksのURLが他の環境と被らないようにします。

app.config.stg.jsの例
module.exports = config => {
return {
/* 省略 */
android: {
/* 省略 */
package: 'jp.fintan.mobile.SantokuApp.stg',
intentFilters: [
{
autoVerify: true,
action: 'VIEW',
data: [
{
scheme: 'https',
},
{
host: 'reactnativesandbox.z11.web.core.windows.net',
},
{
pathPattern: `/stg/question/.*`,
},
{
path: `/stg/demo/app-info`,
},
],
category: ['BROWSABLE', 'DEFAULT'],
},
],
},
/* 省略 */
};
};

上記設定後に、Prebuildを実行すると以下のAndroidManifest.xmlが生成されます。

AndroidManifest.xmlの例
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- ~省略~ -->
<application
android:name=".MainApplication"
<!-- ~省略~ -->
>
<activity
android:name=".MainActivity"
<!-- ~省略~ -->
>
<!-- ~省略~ -->
<intent-filter android:autoVerify="true" data-generated="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="https"/>
<data android:host="reactnativesandbox.z11.web.core.windows.net"/>
<data android:pathPattern="/stg/question/.*"/>
<data android:path="/stg/demo/app-info"/>
</intent-filter>
</activity>
</application>
</manifest>