Skip to content

Commit

Permalink
Ensure the leanback intent is started on Android TV
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier authored and JakeWharton committed Feb 26, 2024
1 parent 4cf6fca commit 583069c
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Process;
import java.util.ArrayList;
Expand All @@ -27,6 +29,7 @@

import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.pm.PackageManager.FEATURE_LEANBACK;

/**
* Process Phoenix facilitates restarting your application process. This should only be used for
Expand Down Expand Up @@ -70,7 +73,16 @@ public static void triggerRebirth(Context context, Intent... nextIntents) {

private static Intent getRestartIntent(Context context) {
String packageName = context.getPackageName();
Intent defaultIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);

PackageManager PackageManager = context.getPackageManager();
Intent defaultIntent = null;
if (Build.VERSION.SDK_INT >= 21 && PackageManager.hasSystemFeature(FEATURE_LEANBACK)) {
// Use leanback intent if available, for Android TV apps.
defaultIntent = PackageManager.getLeanbackLaunchIntentForPackage(packageName);
}
if (defaultIntent == null) {
defaultIntent = PackageManager.getLaunchIntentForPackage(packageName);
}
if (defaultIntent != null) {
return defaultIntent;
}
Expand Down

0 comments on commit 583069c

Please sign in to comment.