Launch App on TV

Many TVs and streaming players include support for launching installed apps. The following is a simplified example of how to launch YouTube on a device.

Launch an app

mDevice.getLauncher().launchApp("YouTube", new Launcher.AppLaunchListener() {
	
	@Override
	public void onError(ServiceCommandError error) {
		Log.d("App Tag", "App Launch error: " + error);
	}
	
	@Override
	public void onSuccess(LaunchSession object) {
		Log.d("App Tag", "App Launch success.");
	}
});

Device-specific app identifiers

On each device (webOS TV, Roku, etc) apps are identified by different values. Here is an example of the different identifiers in use for the YouTube app.

  • webOS: youtube.leanback.v4 (value may change with future updates)
  • Netcast: 0000000000017498 (value may be different on each TV)
  • DIAL: YouTube (listed in DIAL registry)
  • Roku: 837 (Roku-specific channel number)

Launching an app with device-specific identifiers

The following snippet shows how to detect the platform of your device and launch with the appropriate app identifier.

String appId;

if (mDevice.getServiceByName("webOS TV") != null)
    appId = @"youtube.leanback.v4";
else if (mDevice.getServiceByName("Netcast TV") != null)
    appId = @"0000000000017498";
else if (mDevice.getServiceByName("Roku") != null)
    appId = @"837";
else if (mDevice.getServiceByName("DIAL") != null)
    appId = @"YouTube";

if (!appId)
    return;

AppInfo appInfo = new AppInfo(appId);
appInfo.setName("YouTube");

mDevice.getLauncher().launchApp(appInfo, new Launcher.AppLaunchListener() {
	
	@Override
	public void onError(ServiceCommandError error) {
		Log.d("App Tag", "App Launch error: " + error);
	}
	
	@Override
	public void onSuccess(LaunchSession object) {
		Log.d("App Tag", "App Launch success.");
	}
});

AppInfo helper object

You will notice that the previous example refers to an AppInfo object. This object is used internally by Connect SDK to manage an app's protocol-specific properties. If a device supports app list, the app list will return a set of AppInfo objects for each app installed on the TV.

Launching an app with parameters

In most cases, a device's launcher object will allow you to pass launch parameters to your app. Connect SDK has normalized the parameter input type to a keyed set of values. These values are then parsed into the appropriate format for the protocol (XML, JSON, URL params, etc).

JSONObject params = null;
try {
	params = new JSONObject() {{
		put("someProperty", "someValue");
	}};
} catch (JSONException e) {
	e.printStackTrace();
}

mDevice.getLauncher().launchAppWithInfo(appInfo, params, new Launcher.AppLaunchListener() {
	
	@Override
	public void onError(ServiceCommandError error) {
		Log.d("App Tag", "App Launch error: " + error);
	}
	
	@Override
	public void onSuccess(LaunchSession object) {
		Log.d("App Tag", "App Launch success.");
	}
});

A note on launch parameters

Due to the variety of protocols in use, it is strongly recommended that you only use strings for the keys AND values of your parameters.