Android Device Info
This plugin allows you to gather data from your android device form things like, the SwDPI, SDK Version, OS Version...
A full list is written below; Goto functions list
Installing
run npm install cordova-plugin-android-misc-info --save-devs
Making it work
Just add a deviceready
listener into your Angular Controller like:
document.addEventListener('deviceready', function () { // TODO: Add your logic here...});
Then, everything related to the plugin goes inside this.
Example
Let's supose we have a template like:
SDK Version: {{sdkver}}
Then our controller should be:
.controller("aController", ["$scope", function($scope){ $scope.sdkver = "Loading..."; document.addEventListener('deviceready', function () { //Returns a promise. deviceInfo.getSdkVersion().then(function (sdkver) { $scope.sdkver = sdkver; //Then, invoke this if you want your $scope to be updated, because the event is outside of AngulatJS's context. if (!$scope.$$phase){ $scope.$apply(); } }); }); }]);
An alternative, and maybe more clean approach may be this (also may not suit every case):
.controller("aController", ["$scope", function($scope){ $scope.sdkver = "Loading..."; (new Promise((resolve, reject) => { document.addEventListener('deviceready', resolve, false); })).then(() => { deviceInfo.getSdkVersion().then(function (sdkver) { $scope.sdkver = sdkver; //Then, invoke this if you want your $scope to be updated, because the event is outside of AngulatJS's context. if (!$scope.$$phase){ $scope.$apply(); } }); }); }]);
All functions of the object deviceInfo
returns a promise that, when resolved it passes the data to the first argument.
var promise = deviceInfo.getSdkVersion();//OrdeviceInfo.getSdkVersion().then(function(result){ //Do something...}, function(reason){ throw new Error(reason);//This rejects the next promise, if you want...});
So if you call/access the deviceInfo
object inside the deviceready
handler, it should appear as global.
WARN: Calling it outside may cause an error saying that cannot call function x
from undefined deviceInfo
Functions
Function Name | Sample Output |
---|---|
getBoard | MSM8916 |
getBrand | samsung |
getDevice | heatqlte |
getDisplay | KTU84P.G357FZXXU1AOE1 |
getHost | SWDD6204 |
getId | KTU84P |
getManufacturer | samsung |
getModel | SM-G357FZ |
getProduct | heatqltexx |
getTags | release-keys |
getType | user |
getUser | dpi |
getUID | -87008(...) |
getSwDpi | 320 |
getSdkVersion | 19 |
getOsVersion | 4.4.4 |
Example of testing code
Wanna dump your device's data to array? NP, use this:
Object.keys(deviceInfo).forEach(function (v) { deviceInfo[v]('', function(out){ $scope.testOut.push({ name: v, out: out }); });});
Then, somewere before the deviceready
event, place a $scope.testOut = [];
Again, remember to call it inside the deviceready
event. You can use the following template to dump the info:
{{out.name}} {{out.out}}