加入意圖
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
「有意加入」是 Android 發送端的新功能
傳送者應用程式加入「加入」其他應用程式啟動的投放工作階段,或
語音。你將傳送者應用程式設為由 Cast 建立的意圖啟動
將機器學習工作流程自動化
舉例來說,使用語音啟動投放工作階段時,Cast SDK 會建立
可讓使用者控制所有 Android 手機的播放功能
連線至同一網路使用者輕觸通知後,Cast SDK 就會建立
意圖啟動應用程式以加入投放工作階段。
詳情請參閱
CastVideos-Android 範例
瞭解執行 Intent to Join 的實作方式
使用 Android 寄件者
如要啟用這項功能,請在應用程式中執行下列步驟:
確認應用程式目前的 Android Sender SDK 版本高於
11.4.0.在 build.gradle
中:
dependencies {
api 'com.google.android.gms:play-services-cast-framework:11.4.0'
}
將新的意圖篩選器新增至您要處理意圖的活動。
遠端控制通知 (RCN) 會使用意圖來啟動您的應用程式
然後加入投放工作階段
建議您利用
SessionManagerListener
敬上
代管服務
onSessionStarted()
。
或
onSessionStartFailed()
。
請確認整個 Android 系統中的新意圖篩選器都不重複。三
建議您使用 <data>
標記完成此操作,如下所示:
<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="your_app_scheme" android:host="your_app_host"
android:path="your_app_path"/>
</intent-filter>
<data>
標記範例:
<data android:scheme="https" android:host="example.com"
android:path="/cast/join"/>
在定義新意圖篩選器的活動中,呼叫
SessionManager.startSession(Intent)
敬上
在 onResume()
中:
override fun onResume() {
...
val intent = intent
// Intent with format: "<your_app_scheme>://<your_app_host><your_app_path>"
val intentToJoinUri = Uri.parse("https://example.com/cast/join")
if (intent.data != null && intent.data == intentToJoinUri) {
mCastContext.sessionManager.startSession(intent)
}
...
}
敬上
@Override
protected void onResume() {
...
Intent intent = getIntent();
// Intent with format: "<your_app_scheme>://<your_app_host><your_app_path>"
Uri intentToJoinUri = Uri.parse("https://example.com/cast/join");
if (intent.getData() != null && intent.getData().equals(intentToJoinUri)) {
mCastContext.getSessionManager().startSession(intent);
}
...
}
Google Cast 開發人員控制台設定
如要使用 Intent to Join 功能,必須讓應用程式 URI 和套件名稱
已新增至
Google Cast 開發人員控制台。

您的接收器也必須列出並發布,「意圖加入」功能才能運作
正確做法。
如要列出應用程式,請將清單選項切換為「是」並提供標題
一張圖片,以及大小為 512x512 的圖片

設定完成後,您可以透過「遠端控制通知」測試實作結果
(RCN):
- 在 Android 手機上安裝 Google Home 應用程式,然後連上
電話。
- 支援 Cast 的裝置會在相同的網路中設定 Google Home 裝置。
- 使用
Command and Control (CaC) 工具,
其他 Android 或 iOS 裝置,或是透過語音確認網路接收器
應用程式就會啟動
- 稍待幾秒鐘,手機才會收到 RCN,然後輕觸通知即可
觸發意圖意圖應向符合下列條件的應用程式廣播意圖:
使用必要資料註冊意圖,以加入工作階段。
SessionManagerListener.onSessionStarted(T, String)
敬上
就會觸發並加入工作階段
驗證
如果您的應用程式成功加入工作階段,
SessionManagerListener.onSessionStarted(T, String)
敬上
方法。否則
SessionManagerListener.onSessionStartFailed(T, int)
敬上
方法。假設應用程式已能妥善處理這些事件 (針對
例如啟動展開控制器或迷你控制器
採取進一步行動
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eThe "Intent to Join" feature enables Android sender apps to join existing Cast sessions initiated by other apps or voice commands.\u003c/p\u003e\n"],["\u003cp\u003eTo enable this, add a specific intent filter to your activity, update your Android Sender SDK, and configure your app in the Google Cast Developer Console.\u003c/p\u003e\n"],["\u003cp\u003eThe Cast SDK creates an intent that launches your app and allows it to join the session when a user interacts with a Cast notification.\u003c/p\u003e\n"],["\u003cp\u003eVerify successful implementation by checking if \u003ccode\u003eSessionManagerListener.onSessionStarted\u003c/code\u003e or \u003ccode\u003eSessionManagerListener.onSessionStartFailed\u003c/code\u003e is called appropriately.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the CastVideos-Android sample for a working implementation of the Intent to Join feature.\u003c/p\u003e\n"]]],["The \"Intent to Join\" feature allows an Android sender app to join an existing Cast session. To enable it, ensure the app uses Android Sender SDK version 11.4.0 or greater, add a unique intent filter to an activity, and call `SessionManager.startSession(Intent)` in `onResume()`. The app URI and package name must be added to the Google Cast Developer Console, and the receiver must be listed. Tapping a Remote Control Notification triggers an intent, starting a session and calling `onSessionStarted()` if successful, otherwise `onSessionStartFailed()` is called.\n"],null,["# Intent to Join\n\n\"Intent to Join\" is a new feature of the Android Sender that allows a\nsender app to \"join\" a Cast session that has been initiated by other apps or\nvoice. You set up your sender app to be launched by an intent created by Cast\nSDK.\n\nFor example, when using voice to start a Cast session, Cast SDK creates a\nnotification that allows a user to control the playback on all Android phones\non the same network. When the notification is tapped, Cast SDK creates the\nintent to launch your app to join the Cast session.\n\nSee the\n[CastVideos-Android sample](https://github.com/googlecast/CastVideos-android)\nfor a working implementation of Intent to Join.\n\nUsing an Android Sender\n-----------------------\n\nTo enable this feature, perform the following steps in your app:\n\nMake sure your app is already using Android Sender SDK version greater than\n11.4.0. In `build.gradle`: \n\n dependencies {\n api 'com.google.android.gms:play-services-cast-framework:11.4.0'\n }\n\nAdd a new intent filter to an activity where you want to handle the intent. The\nintent will be used by Remote Control Notifications (RCN) to launch your app\nand join a Cast session.\nWe recommend you use the activity where\n[`SessionManagerListener`](/cast/docs/reference/android/com/google/android/gms/cast/framework/SessionManagerListener)\nis hosted, and either\n[`onSessionStarted()`](/cast/docs/reference/android/com/google/android/gms/cast/framework/SessionManagerListener#onSessionStarted(T,%20java.lang.String))\nor\n[`onSessionStartFailed()`](/cast/docs/reference/android/com/google/android/gms/cast/framework/SessionManagerListener#onSessionStartFailed(T,%20int))\nwill be called.\nMake sure the new intent filter is unique across the entire Android system. We\nrecommend you use the `\u003cdata\u003e` tag to do that, as follows: \n\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n \u003cdata android:scheme=\"your_app_scheme\" android:host=\"your_app_host\"\n android:path=\"your_app_path\"/\u003e\n \u003c/intent-filter\u003e\n\nExamples of `\u003cdata\u003e` tag: \n\n \u003cdata android:scheme=\"https\" android:host=\"example.com\"\n android:path=\"/cast/join\"/\u003e\n\nIn the activity where you define the new intent filter, call\n[`SessionManager.startSession(Intent)`](/cast/docs/reference/android/com/google/android/gms/cast/framework/SessionManager#startSession(android.content.Intent))\nin `onResume()`:\nKotlin \n\n```kotlin\noverride fun onResume() {\n ...\n val intent = intent\n // Intent with format: \"\u003cyour_app_scheme\u003e://\u003cyour_app_host\u003e\u003cyour_app_path\u003e\"\n val intentToJoinUri = Uri.parse(\"https://example.com/cast/join\")\n if (intent.data != null && intent.data == intentToJoinUri) {\n mCastContext.sessionManager.startSession(intent)\n }\n ...\n}\n```\nJava \n\n```java\n@Override\nprotected void onResume() {\n ...\n Intent intent = getIntent();\n // Intent with format: \"\u003cyour_app_scheme\u003e://\u003cyour_app_host\u003e\u003cyour_app_path\u003e\"\n Uri intentToJoinUri = Uri.parse(\"https://example.com/cast/join\");\n if (intent.getData() != null && intent.getData().equals(intentToJoinUri)) {\n mCastContext.getSessionManager().startSession(intent);\n }\n ...\n}\n```\n\nGoogle Cast Developer Console setup\n-----------------------------------\n\nTo utilize the Intent to Join feature, the app URI and package name must be\nadded in the\n[Google Cast Developer Console](https://cast.google.com/publish/#/overview).\n\nYour receiver must also be listed and published for Intent to Join to work\nproperly.\n\nTo list your app, toggle the listing option to \"YES\" and provide a title,\ndescription, and a 512x512 graphic for your app.\n\nAfter setup, you can test the implementation with Remote Control Notifications\n(RCN) as below:\n\n1. Install the Google Home App on an Android phone, and connect to Wi-Fi on the phone.\n2. The Cast-enabled device sets up the Google Home device under the same network.\n3. Initiate a Cast session with the Google Home device using the [Command and Control (CaC) Tool](https://casttool.appspot.com/cactool/), another Android or iOS device, or through voice and check if the Web Receiver app is launched.\n4. Wait for a few seconds to get RCN on the phone, and tap the notification to trigger the intent. The intent should be broadcasted to any app that registers the intent with the required data to join the session.\n\n[`SessionManagerListener.onSessionStarted(T, String)`](/cast/docs/reference/android/com/google/android/gms/cast/framework/SessionManagerListener#onSessionStarted(T,%20java.lang.String))\nwill be triggered and join the session.\n\nVerification\n------------\n\nIf your app successfully joins the session,\n[`SessionManagerListener.onSessionStarted(T, String)`](/cast/docs/reference/android/com/google/android/gms/cast/framework/SessionManagerListener#onSessionStarted(T,%20java.lang.String))\nis called. Otherwise,\n[`SessionManagerListener.onSessionStartFailed(T, int)`](/cast/docs/reference/android/com/google/android/gms/cast/framework/SessionManagerListener#onSessionStartFailed(T,%20int))\nis called. Assuming your app already handles those events properly (for\nexample, launching expanded controller or mini controller), you don't have to\ndo anything further."]]