facebook twitter hatena line email

「Unity/URLからアプリ起動」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
 
行4: 行4:
  
 
[[Unity/URLからアプリ起動/iOS]]
 
[[Unity/URLからアプリ起動/iOS]]
 
==Androidの場合==
 
BuildProfilesのAndroid/PlayerSettingで、CustomMainManifestをonにする。
 
 
Assets/Plugins/Android/AndroidManifest.xml にintent-filterを追加する。
 
 
例として、ttps://example.com/hogehogeで起動させたい場合。
 
 
<pre>
 
<?xml version="1.0" encoding="utf-8"?>
 
<manifest
 
    xmlns:android="http://schemas.android.com/apk/res/android"
 
    xmlns:tools="http://schemas.android.com/tools">
 
    <application>
 
        <!--Used when Application Entry is set to Activity, otherwise remove this activity block-->
 
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
 
                  android:theme="@style/UnityThemeSelector">
 
            <intent-filter>
 
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
 
            </intent-filter>
 
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
 
 
        </activity>
 
        <!--Used when Application Entry is set to GameActivity, otherwise remove this activity block-->
 
        <activity android:name="com.unity3d.player.UnityPlayerGameActivity"
 
                  android:theme="@style/BaseUnityGameActivityTheme"
 
                  android:launchMode="singleTask"
 
                  android:exported="true">
 
            <intent-filter>
 
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
 
            </intent-filter>
 
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
 
            <meta-data android:name="android.app.lib_name" android:value="game" />
 
 
            <!-- DeepLink / App Links -->
 
            <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="example.com"
 
                    android:pathPrefix="/hogehoge" />
 
            </intent-filter>
 
        </activity>
 
 
    </application>
 
</manifest>
 
</pre>
 
activityが、"com.unity3d.player.UnityPlayerActivity"と"com.unity3d.player.UnityPlayerGameActivity"があり、"com.unity3d.player.UnityPlayerGameActivity"側にintent-filterをつけた場合は、
 
Unity の Player Settings の "ApplicationEntryPoint" の GameActivity にチェックがついてることを確認。
 
 
activityの"com.unity3d.player.UnityPlayerGameActivity"側に、以下が追加されてることも確認。
 
<pre>
 
android:launchMode="singleTask"
 
android:exported="true"
 
</pre>
 
 
ローカルアプリのフィンガープリント出力。(今入ってるアプリのフィンがプリントを表示)
 
<pre>
 
$ adb shell pm get-app-links com.example.app1
 
  com.example.app1:
 
    ID: fb90da74-68d4-40c7-a197-698907e476de
 
    Signatures: [D8:C9:8D:8D:E9:1F:3C:D8:97:DB:34:2B:D0:E9:66:76:70:28:B9:8B:37:44:32:E2:14:9E:CD:97:70:XX:XX:XX]
 
    Domain verification state:
 
      example.com: verified
 
</pre>
 
 
Webサーバに、
 
example.com/.well-known/assetlinks.jsonを設置する。(例:example.comは適宜変更)
 
<pre>
 
[
 
  {
 
    "relation": ["delegate_permission/common.handle_all_urls"],
 
    "target": {
 
      "namespace": "android_app",
 
      "package_name": "com.example.app1",
 
      "sha256_cert_fingerprints": [
 
        "D8:C9:8D:8D:E9:1F:3C:D8:97:DB:34:2B:D0:E9:66:76:70:28:B9:8B:37:44:32:E2:14:9E:CD:97:70:XX:XX:XX"
 
      ]
 
    }
 
  }
 
]
 
</pre>
 
 
設置が正しいかcurlで確認。
 
<pre>
 
$ curl -I https://example.com/.well-known/assetlinks.json
 
HTTP/2 200
 
server: nginx
 
date: Tue, 02 Dec 2025 22:05:04 GMT
 
content-type: application/json
 
content-length: 328
 
last-modified: Tue, 02 Dec 2025 21:56:17 GMT
 
etag: "148-644ff2a4d2500"
 
accept-ranges: bytes
 
</pre>
 
Webサーバに設置した直後だと、エラーになるが、しばらくすると動作するようになった。
 
 
===本番のフィンガープリントの箇所===
 
play.google.com/consoleの、テストとリリース/アプリの完全性/アプリの署名/アプリ署名鍵の証明書のSHA-1証明書のフィンガープリントがあるので、その文字列を、webサーバへupする。
 
 
===確認方法===
 
アプリのブラウザで、以下のurlを開いて、アプリが起動すれば良い。
 
<pre>
 
https://example.com/hogehoge
 
</pre>
 
 
===get-app-linksコマンドで、verifiedが出れば問題ないはず===
 
今入ってるアプリのフィンガープリントが正しいか確認。verifiedが出れば正しい。
 
<pre>
 
adb shell pm get-app-links com.example.app1
 
  com.example.app1:
 
    ID: fb90da74-68d4-40c7-a197-698907e476de
 
    Signatures: [D8:C9:8D:8D:E9:1F:3C:D8:97:DB:34:2B:D0:E9:66:76:70:28:B9:8B:37:44:32:E2:14:9E:CD:97:70:XX:XX:XX]
 
    Domain verification state:
 
      example.com: verified
 
</pre>
 
 
===.well-known/assetlinks.json内にtargetを2つ設置する場合===
 
<pre>
 
[
 
  {
 
    "relation": ["delegate_permission/common.handle_all_urls"],
 
    "target": {
 
      "namespace": "android_app",
 
      "package_name": "com.example.app1",
 
      "sha256_cert_fingerprints": [
 
        "AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA:AA"
 
      ]
 
    }
 
  },
 
  {
 
    "relation": ["delegate_permission/common.handle_all_urls"],
 
    "target": {
 
      "namespace": "android_app",
 
      "package_name": "com.example.app2",
 
      "sha256_cert_fingerprints": [
 
        "BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB:BB"
 
      ]
 
    }
 
  }
 
]
 
</pre>
 
===動作図解===
 
<pre>
 
[ユーザー] ──URLタップ──▶ [Android OS]
 
                                │
 
                                ├─ アプリある? → Yes → 直で起動
 
                                │
 
                                └─ アプリない → URL保存(パラメータ付)
 
                                              │
 
                                              ▼
 
                                      [Google Play ストア]
 
                                              │
 
                                    インストール&起動
 
                                              │
 
                                              ▼
 
                              OS が保存していた DeepLink を渡す
 
                                              │
 
                                              ▼
 
                                          [アプリ]
 
</pre>
 
 
===同じドメインで、別のアプリを開く場合===
 
2つのAndroidManifest.xmlのpathPrefixを別にする。param形式ではだめで、/で繋いで、URIを変更する。
 
 
1つ目アプリのAndroidManifest.xml
 
<pre>
 
<data
 
                    android:scheme="https"
 
                    android:host="example.com"
 
                    android:pathPrefix="/hogehoge/link/index/apptype/app1" />
 
</pre>
 
2つ目アプリのAndroidManifest.xml
 
<pre>
 
<data
 
                    android:scheme="https"
 
                    android:host="example.com"
 
                    android:pathPrefix="/hogehoge/link/index/apptype/app2" />
 
</pre>
 

2025年12月5日 (金) 02:11時点における最新版

Unity/URLからアプリ起動/基本

Unity/URLからアプリ起動/Android

Unity/URLからアプリ起動/iOS