In vanilla JS you can use the plugin as follows:
window.plugins.PowerManagement.acquire( successCallback, errorCallback );
window.plugins.PowerManagement.release( successCallback, errorCallback );
window.plugins.PowerManagement.dim( successCallback, errorCallback );
From cordova 1.6+ plugin architecture has changed pretty extreme, you have to do:
cordova.require('cordova/plugin/powermanagement').acquire( successCallback, errorCallback );
cordova.require('cordova/plugin/powermanagement').release( successCallback, errorCallback );
cordova.require('cordova/plugin/powermanagement').dim( successCallback, errorCallback );
Changing this to a ngCordovoa like factory, you would end up with something like this:
.factory( '$cordovaPowerManagement', [
'$q',
'$window',
function ( $q, $window ) {
return {
acquire: function () {
var q = $q.defer();
$window.plugins.PowerManagement.acquire( function ( result ) {
q.resolve( result );
}, function ( err ) {
q.reject( err );
} );
return q.promise;
},
release: function () {
var q = $q.defer();
$window.plugins.PowerManagement.release( function ( result ) {
q.resolve( result );
}, function ( err ) {
q.reject( err );
} );
return q.promise;
},
dim : function () {
var q = $q.defer();
$window.plugins.PowerManagement.dim( function ( result ) {
q.resolve( result );
}, function ( err ) {
q.reject( err );
} );
return q.promise;
}
};
}
] );
You could add this factory to your app or controller, and you could then inject $cordovaPowerManagement
to your controller, and use the functions, functions will return a promise.
Take a note: I did not test above code, I just assembled this from the plugin documentation and took some code snippets from ngCordova… Please let me know if it works!
Hope this helps