diff --git a/utils/utils.android.ts b/utils/utils.android.ts index 4cd78710b..bb79d4406 100644 --- a/utils/utils.android.ts +++ b/utils/utils.android.ts @@ -130,4 +130,19 @@ export module ad { export function GC() { gc(); +} + +export function openUrl(location: string): boolean { + var context = ad.getApplicationContext(); + try { + var intent = new android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(location.trim())); + intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK); + + context.startActivity(intent); + } catch (e) { + // We Don't do anything with an error. We just output it + console.error("Error in OpenURL", e); + return false; + } + return true; } \ No newline at end of file diff --git a/utils/utils.d.ts b/utils/utils.d.ts index e6b560f42..b044b2b20 100644 --- a/utils/utils.d.ts +++ b/utils/utils.d.ts @@ -173,4 +173,10 @@ * @param source The JSON or JSONP string. */ export function parseJSON(source: string): any + + /** + * Opens url. + * @param url The url. + */ + export function openUrl(url: string): boolean } diff --git a/utils/utils.ios.ts b/utils/utils.ios.ts index e479ffa07..b96b9de01 100644 --- a/utils/utils.ios.ts +++ b/utils/utils.ios.ts @@ -50,7 +50,7 @@ export module ios { var greenRef = new interop.Reference(); var blueRef = new interop.Reference(); var alphaRef = new interop.Reference(); - + uiColor.getRedGreenBlueAlpha(redRef, greenRef, blueRef, alphaRef); var red = redRef.value * 255; var green = greenRef.value * 255; @@ -142,8 +142,22 @@ export module ios { rootView.measure(widthSpec, heightSpec); rootView.layout(left, top, width, height); } -} +} export function GC() { __collect(); +} + +export function openUrl(location: string): boolean { + try { + var url = NSURL.URLWithString(location.trim()); + if (UIApplication.sharedApplication().canOpenURL(url)) { + return UIApplication.sharedApplication().openURL(url); + } + } + catch (e) { + // We Don't do anything with an error. We just output it + console.error("Error in OpenURL", e); + } + return false; } \ No newline at end of file