Skip to content

Fix and simplify opening in browser (openUrlInBrowser)#12605

Merged
Stypox merged 1 commit intodevfrom
open-in-browser
Sep 30, 2025
Merged

Fix and simplify opening in browser (openUrlInBrowser)#12605
Stypox merged 1 commit intodevfrom
open-in-browser

Conversation

@fynngodau
Copy link
Copy Markdown
Member

@fynngodau fynngodau commented Sep 5, 2025

The code was not previously working in case no default browser is set[1] AND NewPipe is set as default handler for the link in question.

We improve it by telling the system to choose the target app as if the URI was http://, which makes more sense than expecting a default browser to be set and NewPipe trying to query that.

[1]: also the case if platform refuses to tell an app what the user's default browser is, which I observed on CalyxOS.

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Fixes the following issue(s)

For technical reasons we do not add the behavior suggested in #9403 as we still mirror the behavior as if http:// is opened – unfortunately Android does not offer us a proper way to selectively exclude a specific activity (i.e. ourselves) from the target list (see also my Implementation note comment in the openAppChooser code). cc @SebiderSushi

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.

Direct download link: app(2).zip

Due diligence

@fynngodau fynngodau requested a review from Stypox September 5, 2025 15:43
@github-actions github-actions Bot added the size/medium PRs with less than 250 changed lines label Sep 5, 2025
The code was not previously working in case no default browser is set[1]
AND NewPipe is set as default handler for the link in question.

We improve it by telling the system to choose the target app as if the
URI was `http://`, which works even if the user has not set a default
browser.

[1]: also the case if platform refuses to tell an app what the user's
default browser is, which I observed on CalyxOS.
Copy link
Copy Markdown
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this should be the behavior we use, however I would like @AudricV to check this

@Stypox Stypox requested a review from AudricV September 5, 2025 15:52
@Stypox Stypox added this to v0.28.x Sep 6, 2025
@github-project-automation github-project-automation Bot moved this to Todo in v0.28.x Sep 6, 2025
@Stypox Stypox moved this from Todo to In Progress in v0.28.x Sep 6, 2025
@Stypox Stypox added the bug Issue is related to a bug label Sep 17, 2025
@Stypox
Copy link
Copy Markdown
Member

Stypox commented Sep 30, 2025

I'm merging this for now, so people can start testing it in nightlies. Since this is a very small PR, it can always be reverted if it creates issues.

@Stypox Stypox merged commit 00f6203 into dev Sep 30, 2025
6 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in v0.28.x Sep 30, 2025
Comment on lines +177 to +180
// (Implementation note: if the URL is one for which NewPipe itself
// is set as handler on Android >= 12, we actually remove the only eligible app
// for this link, and browsers will not be offered to the user. For that, use
// `openUrlInBrowser`.)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should (I tested this in the Android 14 Developer Preview 2 on March 2023) be able use Intent.EXTRA_ALTERNATE_INTENTS (Android API 23+) to show all apps that can open a given intent even with web restrictions on Android >= 12. However, we need to have access to queries of all intents we use (so http, https, market, as we target Kodi's package directly):

final List<ResolveInfo> resolveInfoList;

// Use PackageManager.MATCH_ALL, as we want the list of apps which can handle a web intent
// and not only the default app
// This flag doesn't include disabled or uninstalled apps with data kept (they would be not
// accessible anyway, as this requires the QUERY_ALL_PACKAGES permission)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    resolveInfoList = context.getPackageManager()
            .queryIntentActivities(intent,
                    PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_ALL));
} else {
    resolveInfoList = context.getPackageManager()
            .queryIntentActivities(intent, PackageManager.MATCH_ALL);
}

final Intent[] intents = resolveInfoList.stream()
        .map(resolveInfo -> new Intent(Intent.ACTION_VIEW, urlUri)
                .setPackage(resolveInfo.activityInfo.packageName))
        .toArray(Intent[]::new);

// Passing an Intent which doesn't match any activity, as we don't want any other app in the
// system chooser than the ones we got earlier
// In this example an ACTION_VIEW intent with an empty URI is used
final Intent chooserIntent = createChooserIntent(
        context, new Intent(Intent.ACTION_VIEW, Uri.EMPTY), true);
// Intent.EXTRA_ALTERNATE_INTENTS extra allows to pass an unlimited amount of intents
chooserIntent.putExtra(Intent.EXTRA_ALTERNATE_INTENTS, intents);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I see how this could work, we're basically recreating the chooser dialog. You propose adding this just for the case where openUrlInBrowser fails, right? Not for the general openAppChooser implementation, right? Because openAppChooser is also used in shareText which is not an URL.

@AudricV AudricV deleted the open-in-browser branch November 5, 2025 10:35
@TobiGr TobiGr mentioned this pull request Dec 21, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue is related to a bug size/medium PRs with less than 250 changed lines

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants