mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(android): openUrl (#10161)
This commit is contained in:
committed by
GitHub
parent
5b6e4d6898
commit
451c3cfe43
@@ -22,20 +22,11 @@ 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
|
||||
Trace.write('Error in OpenURL', Trace.categories.Error, Trace.messageType.error);
|
||||
// We don't do anything with an error. We just output it
|
||||
Trace.write(`Failed to start activity for handling URL: ${location}`, Trace.categories.Error, Trace.messageType.error);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user