Fix help display on some Android TV devices

This commit is contained in:
Cameron Gutman 2017-11-25 15:08:22 -08:00
parent 5c865e7f36
commit b37a2dea57

View File

@ -2,22 +2,42 @@ package com.limelight.utils;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import com.limelight.HelpActivity; import com.limelight.HelpActivity;
public class HelpLauncher { 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) { private static void launchUrl(Context context, String url) {
// Try to launch the default browser // Try to launch the default browser
try { try {
// Fire TV devices will lie and say they do have a browser Intent i = new Intent(Intent.ACTION_VIEW);
// even though the OS just shows an error dialog if we i.setData(Uri.parse(url));
// try to use it.
if (!"Amazon".equalsIgnoreCase(Build.MANUFACTURER)) { // Several Android TV devices will lie and say they do have a browser
Intent i = new Intent(Intent.ACTION_VIEW); // even though the OS just shows an error dialog if we try to use it. We need to
i.setData(Uri.parse(url)); // 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); context.startActivity(i);
return; return;
} }