Fixed view/package in some cases

pull/208/head
M66B 2 years ago
parent 88ea3f56c3
commit 353a38ca2f

@ -534,7 +534,16 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
} catch (Throwable ex) { } catch (Throwable ex) {
if (this instanceof ActivityMain) if (this instanceof ActivityMain)
throw ex; throw ex;
Helper.reportNoViewer(this, intent, ex); if (intent.getPackage() == null)
Helper.reportNoViewer(this, intent, ex);
else {
intent.setPackage(null);
try {
super.startActivity(intent);
} catch (Throwable exex) {
Helper.reportNoViewer(this, intent, exex);
}
}
} }
} }
@ -545,7 +554,16 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
Log.logExtras(intent); Log.logExtras(intent);
super.startActivityForResult(intent, requestCode); super.startActivityForResult(intent, requestCode);
} catch (Throwable ex) { } catch (Throwable ex) {
Helper.reportNoViewer(this, intent, ex); if (intent.getPackage() == null)
Helper.reportNoViewer(this, intent, ex);
else {
intent.setPackage(null);
try {
super.startActivityForResult(intent, requestCode);
} catch (Throwable exex) {
Helper.reportNoViewer(this, intent, exex);
}
}
} }
} }

@ -412,10 +412,6 @@ public class Helper {
} }
private static boolean hasCustomTabs(Context context, Uri uri, String pkg) { private static boolean hasCustomTabs(Context context, Uri uri, String pkg) {
String scheme = (uri == null ? null : uri.getScheme());
if (!"http".equals(scheme) && !"https".equals(scheme))
return false;
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();
Intent view = new Intent(Intent.ACTION_VIEW, uri); Intent view = new Intent(Intent.ACTION_VIEW, uri);
@ -826,12 +822,27 @@ public class Helper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String open_with_pkg = prefs.getString("open_with_pkg", null); String open_with_pkg = prefs.getString("open_with_pkg", null);
boolean open_with_tabs = prefs.getBoolean("open_with_tabs", true);
boolean has = hasCustomTabs(context, uri, open_with_pkg); if (!UriHelper.isHyperLink(uri)) {
open_with_pkg = null;
open_with_tabs = false;
}
Log.i("View=" + uri + " browse=" + browse + " task=" + task + " pkg=" + open_with_pkg + " has=" + has); if (open_with_pkg != null && !isInstalled(context, open_with_pkg)) {
open_with_pkg = null;
open_with_tabs = false;
}
if (browse || !has) { if (open_with_tabs && !hasCustomTabs(context, uri, open_with_pkg))
open_with_tabs = false;
Log.i("View=" + uri +
" browse=" + browse +
" task=" + task +
" pkg=" + open_with_pkg + ":" + open_with_tabs);
if (browse || !open_with_tabs) {
try { try {
Intent view = new Intent(Intent.ACTION_VIEW); Intent view = new Intent(Intent.ACTION_VIEW);
if (mimeType == null) if (mimeType == null)
@ -840,9 +851,7 @@ public class Helper {
view.setDataAndType(uri, mimeType); view.setDataAndType(uri, mimeType);
if (task) if (task)
view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (UriHelper.isHyperLink(uri) && view.setPackage(open_with_pkg);
open_with_pkg != null && isInstalled(context, open_with_pkg))
view.setPackage(open_with_pkg);
context.startActivity(view); context.startActivity(view);
} catch (Throwable ex) { } catch (Throwable ex) {
reportNoViewer(context, uri, ex); reportNoViewer(context, uri, ex);
@ -890,9 +899,7 @@ public class Helper {
CustomTabsIntent customTabsIntent = builder.build(); CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers); customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers);
customTabsIntent.intent.setPackage(open_with_pkg);
if (open_with_pkg != null && isInstalled(context, open_with_pkg))
customTabsIntent.intent.setPackage(open_with_pkg);
try { try {
customTabsIntent.launchUrl(context, uri); customTabsIntent.launchUrl(context, uri);

Loading…
Cancel
Save