Merge pull request #700 from NativeScript/openUrl

openUrl added
This commit is contained in:
Vladimir Enchev
2015-09-09 15:32:18 +03:00
3 changed files with 37 additions and 2 deletions

View File

@ -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;
}

6
utils/utils.d.ts vendored
View File

@ -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
}

View File

@ -50,7 +50,7 @@ export module ios {
var greenRef = new interop.Reference<number>();
var blueRef = new interop.Reference<number>();
var alphaRef = new interop.Reference<number>();
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;
}