diff --git a/examples/tv-app/android/App/platform-app/src/main/AndroidManifest.xml b/examples/tv-app/android/App/platform-app/src/main/AndroidManifest.xml
index b6e00cd75d0365..476faa2030c7a2 100644
--- a/examples/tv-app/android/App/platform-app/src/main/AndroidManifest.xml
+++ b/examples/tv-app/android/App/platform-app/src/main/AndroidManifest.xml
@@ -26,6 +26,9 @@
tools:ignore="QueryAllPackagesPermission" />
+
+
+
tasks = activityManager.getRunningTasks(1);
+ if (tasks != null && !tasks.isEmpty()) {
+ ActivityManager.RunningTaskInfo taskInfo = tasks.get(0);
+ String packageName =
+ taskInfo.topActivity != null ? taskInfo.topActivity.getPackageName() : "";
+ return packageName.equals(contentAppPackageName);
+ }
+ return false;
+ }
+
public String sendCommand(int endpointId, long clusterId, long commandId, String commandPayload) {
Log.d(TAG, "Received a command for endpointId " + endpointId + ". Message " + commandPayload);
@@ -26,6 +55,17 @@ public String sendCommand(int endpointId, long clusterId, long commandId, String
ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().values(),
endpointId);
if (discoveredApp != null) {
+ // Intercept NavigateTarget and LaunchContent commands and launch content app if necessary
+ if (isForegroundCommand(clusterId, commandId)) {
+ // Check if contentapp main/launch activity is already in foreground before launching.
+ if (!isAppInForeground(discoveredApp.getAppName())) {
+ Intent launchIntent =
+ context.getPackageManager().getLaunchIntentForPackage(discoveredApp.getAppName());
+ if (launchIntent != null) {
+ context.startActivity(launchIntent);
+ }
+ }
+ }
Log.d(TAG, "Sending a command for endpointId " + endpointId + ". Message " + commandPayload);
return ContentAppAgentService.sendCommand(
context, discoveredApp.getAppName(), clusterId, commandId, commandPayload);