fix(android): WebView url and event handling (#10147) (#10148)

closes https://github.com/NativeScript/NativeScript/issues/10147
This commit is contained in:
Prabu Devarrajan
2023-01-03 18:38:33 -08:00
committed by GitHub
parent 00944bb1b5
commit 84440876fe
2 changed files with 9 additions and 2 deletions

View File

@@ -29,8 +29,7 @@ function initializeWebViewClient(): void {
// Handle schemes like mailto, tel, etc
if (!android.webkit.URLUtil.isNetworkUrl(url)) {
openUrl(url);
return true;
return openUrl(url);
}
return false;

View File

@@ -22,8 +22,16 @@ export function openUrl(location: string): boolean {
const context = ad.getApplicationContext();
try {
const intent = new android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(location.trim()));
const packageManager = context.getPackageManager();
intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
// Handle schemes like mailto, tel, etc
if (intent.resolveActivity(packageManager) == null) {
Trace.write('Unable to open ' + location + '. Make sure to add queries element(https://developer.android.com/guide/topics/manifest/queries-element) matching the scheme to the AndroidManifest.xml file.', Trace.categories.Error, Trace.messageType.error);
return false;
}
context.startActivity(intent);
} catch (e) {
// We Don't do anything with an error. We just output it