Intent to Join

"Intent to Join" is a new feature of the CAF Android Sender which 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.

Enable Intent to Join

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

Make sure your app is already using CAF 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" />
  <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():

@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 must be added in the Google Cast Developer Console.

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. In Google Home App, set up the Google Home device under the same network.
  3. Initiate a voice casting with Google Home device, and check if the receiver app is launched on the device.
  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.