Device: Android
Target Version: 25
Cordova version: 7.0.1
I'm using cordova-plugin-geolocation https://www.npmjs.com/package/cordova-plugin-geolocation but with some devices doesn't work. I tried the application with these devices:
CODE:
navigator.geolocation.getCurrentPosition(onSuccessPoint, onErrorPoint,{ timeout:10000 });
var onSuccessPoint = function (position) {
///SUCCESS CODE
}
function onErrorPoint(error) {
//ERROR CODE
}
You app must run in background mode , if your app not white listed under battery optimization your app won't run. use this cordova plugin to white list your app from battery optimization,
Install
cordova plugin add https://github.com/thomas550i/cordova-plugin-doze-Optimize
Javascript code
cordova.plugins.DozeOptimize.IsIgnoringBatteryOptimizations(function (responce){
console.log("IsIgnoringBatteryOptimizations: "+responce);
if(responce=="false")
{
cordova.plugins.DozeOptimize.RequestOptimizations(function (responce){
console.log(responce);
}, function (error){
console.error("BatteryOptimizations Request Error"+error);
});
}
else
{
console.log("Application already Ignoring Battery Optimizations");
}
}, function (error){
console.error("IsIgnoringBatteryOptimizations Error"+error);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.