Skip to content

Commit c2968a3

Browse files
committed
Use non-deprecated resolveActivity method on API 33+
But such method is not available before API 33
1 parent 600ebda commit c2968a3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

  • app/src/main/java/org/schabi/newpipe/util/external_communication

app/src/main/java/org/schabi/newpipe/util/external_communication/ShareUtils.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,16 @@ public static void installApp(@NonNull final Context context, final String packa
7272
public static void openUrlInBrowser(@NonNull final Context context, final String url) {
7373
// Resolve using a generic http://, so we are sure to get a browser and not e.g. the yt app.
7474
// Note that this requires the `http` schema to be added to `<queries>` in the manifest.
75-
final ResolveInfo defaultBrowserInfo = context.getPackageManager().resolveActivity(
76-
new Intent(Intent.ACTION_VIEW, Uri.parse("http://")),
77-
PackageManager.MATCH_DEFAULT_ONLY);
75+
final ResolveInfo defaultBrowserInfo;
76+
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"));
77+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
78+
defaultBrowserInfo = context.getPackageManager().resolveActivity(browserIntent,
79+
PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY));
80+
} else {
81+
defaultBrowserInfo = context.getPackageManager().resolveActivity(browserIntent,
82+
PackageManager.MATCH_DEFAULT_ONLY);
83+
}
84+
7885
if (defaultBrowserInfo == null) {
7986
// No app installed to open a web url
8087
Toast.makeText(context, R.string.no_app_to_open_intent, Toast.LENGTH_LONG).show();

0 commit comments

Comments
 (0)