Intent to Join

"Intent to Join" is a new feature of the Android Sender that allows a sender app to "join" a Cast session that has been initiated by other apps or voice. You set up your sender app to be launched by an intent created by Cast SDK.

For example, when using voice to start a Cast session, Cast SDK creates a notification that allows a user to control the playback on all Android phones on the same network. When the notification is tapped, Cast SDK creates the intent to launch your app to join the Cast session.

See the CastVideos-Android sample for a working implementation of Intent to Join.

Using an Android Sender

To enable this feature, perform the following steps in your app:

Make sure your app is already using Android Sender SDK version greater than 11.4.0. In build.gradle:

dependencies {
    api 'com.google.android.gms:play-services-cast-framework:11.4.0'
}

Add a new intent filter to an activity where you want to handle the intent. The intent will be used by Remote Control Notifications (RCN) to launch your app and join a Cast session. We recommend you use the activity where SessionManagerListener is hosted, and either onSessionStarted() or onSessionStartFailed() will be called. Make sure the new intent filter is unique across the entire Android system. We recommend you use the <data> tag to do that, as follows:

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

Examples of <data> tag:

<data android:scheme="https" android:host="example.com"
      android:path="/cast/join"/>

In the activity where you define the new intent filter, call SessionManager.startSession(Intent) in onResume():

Kotlin
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)
    }
    ...
}
Java
@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 Developer Console setup

To utilize the Intent to Join feature, the app URI and package name must be added in the Google Cast Developer Console.

Your receiver must also be listed and published for Intent to Join to work properly.

To list your app, toggle the listing option to "YES" and provide a title, description, and a 512x512 graphic for your app.

After setup, you can test the implementation with Remote Control Notifications (RCN) as below:

  1. Install the Google Home App on an Android phone, and connect to Wi-Fi on the phone.
  2. The Cast-enabled device sets up the Google Home device under the same network.
  3. Initiate a Cast session with the Google Home device using the Command and Control (CaC) Tool, another Android or iOS device, or through voice and check if the Web Receiver app is launched.
  4. 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.

SessionManagerListener.onSessionStarted(T, String) will be triggered and join the session.

Verification

If your app successfully joins the session, SessionManagerListener.onSessionStarted(T, String) is called. Otherwise, SessionManagerListener.onSessionStartFailed(T, int) is called. Assuming your app already handles those events properly (for example, launching expanded controller or mini controller), you don’t have to do anything further.