Skip to content

Commit

Permalink
Fix help display on some Android TV devices
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Nov 25, 2017
1 parent 5c865e7 commit b37a2de
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions app/src/main/java/com/limelight/utils/HelpLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,42 @@

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;

import com.limelight.HelpActivity;

public class HelpLauncher {

private static boolean isKnownBrowser(Context context, Intent i) {
ResolveInfo resolvedActivity = context.getPackageManager().resolveActivity(i, PackageManager.MATCH_DEFAULT_ONLY);
if (resolvedActivity == null) {
// No browser
return false;
}

String name = resolvedActivity.activityInfo.name;
if (name == null) {
return false;
}

name = name.toLowerCase();
return name.contains("chrome") || name.contains("firefox");
}

private static void launchUrl(Context context, String url) {
// Try to launch the default browser
try {
// Fire TV devices will lie and say they do have a browser
// even though the OS just shows an error dialog if we
// try to use it.
if (!"Amazon".equalsIgnoreCase(Build.MANUFACTURER)) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));

// Several Android TV devices will lie and say they do have a browser
// even though the OS just shows an error dialog if we try to use it. We need to
// be a bit more clever on these devices and detect if the browser is a legitimate
// browser or just a fake error message activity.
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK) ||
isKnownBrowser(context, i)) {
context.startActivity(i);
return;
}
Expand Down

0 comments on commit b37a2de

Please sign in to comment.