设备: Android
目标版本: 25
Cordova版本: 7.0.1
我正在使用cordova-plugin-geolocation https://www.npmjs.com/package/cordova-plugin-geolocation,但有些设备不起作用。我试过这个应用程序 使用这些设备:
代码:
navigator.geolocation.getCurrentPosition(onSuccessPoint, onErrorPoint,{ timeout:10000 });
var onSuccessPoint = function (position) {
///SUCCESS CODE
}
function onErrorPoint(error) {
//ERROR CODE
}
答案 0 :(得分:0)
您的应用必须在后台模式下运行,如果您的应用未在电池优化下列出为白色,则您的应用将无法运行。使用此cordova插件通过电池优化将您的应用列入白名单,
安装
cordova plugin add https://github.com/thomas550i/cordova-plugin-doze-Optimize
JavaScript代码
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);
});