Added user agent string and selected language to the platform module

This commit is contained in:
Darin Dimitrov
2015-04-22 11:20:10 +03:00
parent 605fc4a209
commit a80a073e17
3 changed files with 51 additions and 0 deletions

View File

@@ -18,6 +18,8 @@ export class device implements definition.device {
private static _sdkVersion: string;
private static _deviceType: string;
private static _uuid: string;
private static _userAgent: string;
private static _language: string;
static get os(): string {
return platformNames.android;
@@ -81,6 +83,25 @@ export class device implements definition.device {
return device._uuid;
}
static get userAgent(): string {
if (!device._userAgent) {
var context = application.android.context;
device._userAgent = new android.webkit.WebView(context).getSettings().getUserAgentString();
}
return device._userAgent;
}
static get language(): string {
if (!device._language) {
var context = application.android.context;
var locale = context.getResources().getConfiguration().locale;
device._language = locale.getDefault().toString();
}
return device._language;
}
}
var mainScreenInfo: definition.ScreenMetrics;

View File

@@ -56,6 +56,17 @@ declare module "platform" {
* Gets the uuid
*/
static uuid: string;
/**
* Gets the user agent string as it would be reported by the
* device built-in web browser control
*/
static userAgent: string;
/**
* Gets the preferred language. For example "en" or "en_US"
*/
static language: string;
}
/**

View File

@@ -14,6 +14,8 @@ export class device implements definition.device {
private static _osVersion: string;
private static _sdkVersion: string;
private static _deviceType: string;
private static _userAgent: string;
private static _language: string;
static get manufacturer(): string {
return "Apple";
@@ -74,6 +76,23 @@ export class device implements definition.device {
return app_uuid;
}
static get userAgent(): string {
if (!device._userAgent) {
device._userAgent = new UIWebView().stringByEvaluatingJavaScriptFromString('navigator.userAgent');
}
return device._userAgent;
}
static get language(): string {
if (!device._language) {
var languages = NSLocale.preferredLanguages();
device._language = languages[0];
}
return device._language;
}
}
var mainScreenInfo: definition.ScreenMetrics = null;