forked from EddyVerbruggen/nativescript-appversion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappversion.android.js
executable file
·67 lines (61 loc) · 2.16 KB
/
appversion.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var application = require("tns-core-modules/application");
exports.getAppId = function() {
return new Promise(function(resolve, reject) {
function _resolve() {
var context = application.android.context;
resolve(context.getPackageName());
}
try {
if (application.android.context) {
_resolve();
} else {
// if this is called before application.start() wait for the event to fire
application.on(application.launchEvent, _resolve);
}
} catch (ex) {
console.log("Error in appversion.getAppId: " + ex);
reject(ex);
}
});
};
exports.getAppIdSync = function() {
return application.android.context.getPackageName();
};
exports.getVersionName = function() {
return new Promise(function(resolve, reject) {
function _resolve() {
var packageManager = application.android.context.getPackageManager();
resolve(packageManager.getPackageInfo(application.android.context.getPackageName(), 0).versionName);
}
try {
if (application.android.context) {
_resolve();
} else {
// if this is called before application.start() wait for the event to fire
application.on(application.launchEvent, _resolve);
}
} catch (ex) {
console.log("Error in appversion.getVersionName: " + ex);
reject(ex);
}
});
};
exports.getVersionNameSync = function() {
var packageManager = application.android.context.getPackageManager();
return packageManager.getPackageInfo(application.android.context.getPackageName(), 0).versionName;
};
exports.getVersionCode = function() {
return new Promise(function(resolve, reject) {
try {
var packageManager = application.android.context.getPackageManager();
resolve(packageManager.getPackageInfo(application.android.context.getPackageName(), 0).versionCode.toString());
} catch (ex) {
console.log("Error in appversion.getVersionCode: " + ex);
reject(ex);
}
});
};
exports.getVersionCodeSync = function() {
var packageManager = application.android.context.getPackageManager();
return packageManager.getPackageInfo(application.android.context.getPackageName(), 0).versionCode.toString();
};