Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix app link in in-app browser(#45064) #1831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,17 @@ public static boolean openInExternalApp(Context context, String url, boolean all
try {
if (isTonsite(url) || isInternalUrl(url, null)) return false;
Uri uri = Uri.parse(url);
url = Browser.replace(
uri,
uri.getScheme() == null ? "https" : uri.getScheme(),
null, uri.getHost() != null ? uri.getHost().toLowerCase() : uri.getHost(),
TextUtils.isEmpty(uri.getPath()) ? "/" : uri.getPath()
);
uri = Uri.parse(url);
if (isAppLinkStyle(uri)) {
url = uri.toString();
} else {
url = Browser.replace(
uri,
uri.getScheme() == null ? "https" : uri.getScheme(),
null, uri.getHost() != null ? uri.getHost().toLowerCase() : uri.getHost(),
TextUtils.isEmpty(uri.getPath()) ? "/" : uri.getPath()
);
uri = Uri.parse(url);
}
final boolean isIntentScheme = url.startsWith("intent://") || uri.getScheme() != null && uri.getScheme().equalsIgnoreCase("intent");
if (isIntentScheme && !allowIntent) return false;
final Intent intent = isIntentScheme ?
Expand Down Expand Up @@ -830,4 +834,17 @@ public static String replace(Uri originalUri, String newScheme, String newUserIn
return modifiedUriBuilder.toString();
}

private static boolean isAppLinkStyle(Uri uri) {
if (uri == null || uri.getScheme() == null) {
return false;
}

// App links typically have:
// 1. A scheme
// 2. No authority/host
// 3. Scheme-specific part directly after colon
return uri.getHost() == null &&
uri.getSchemeSpecificPart() != null &&
!uri.getSchemeSpecificPart().startsWith("//");
}
}