From 4cc653fdf1313a3998bf816059cdeb9abab187ea Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 7 Feb 2023 22:39:12 +0100 Subject: [PATCH] Fix opening links on Android 12+ --- .../external_communication/ShareUtils.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java b/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java index 332298b22..06dd3f945 100644 --- a/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java @@ -90,19 +90,16 @@ public final class ShareUtils { // No browser set as default (doesn't work on some devices) openAppChooser(context, intent, true); } else { - if (defaultPackageName.isEmpty()) { - // No app installed to open a web url - Toast.makeText(context, R.string.no_app_to_open_intent, Toast.LENGTH_LONG).show(); - return false; - } else { - try { + try { + // will be empty on Android 12+ + if (!defaultPackageName.isEmpty()) { intent.setPackage(defaultPackageName); - context.startActivity(intent); - } catch (final ActivityNotFoundException e) { - // Not a browser but an app chooser because of OEMs changes - intent.setPackage(null); - openAppChooser(context, intent, true); } + context.startActivity(intent); + } catch (final ActivityNotFoundException e) { + // Not a browser but an app chooser because of OEMs changes + intent.setPackage(null); + openAppChooser(context, intent, true); } }