I am trying to make stepcounter app in javascript with cordova, but pedometer.startPedometerUpdates(successHandler, onError) always returns error handler (never successHandler)
I am using cordova-plugin-pedometer https://www.npmjs.com/package/cordova-plugin-pedometer There is written: The success handler is executed when data is available and is called repeatedly from a background thread as new data arrives.
but as I said my successHandler never executes, so in my opinion it is not called repeatedly or there are no data to work with, but I don't know how to solve it.
I know that there are 2 questions which are close to my question, but there are not helpful answers. Cordova Plugin Pedometers How to use the pedometer plugin?
my code:
var app = {
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
onDeviceReady: function() {
//PEDOMETER
var successHandler = function(data) {
// pedometerData.startDate; -> ms since 1970
// pedometerData.endDate; -> ms since 1970
console.log('step');
alert("step");
alert(data.numberOfSteps + " " + data.distance);
// pedometerData.distance;
// pedometerData.floorsAscended;
// pedometerData.floorsDescended;
};
var onError = function(){
//alert("pedometer failure");
};
var successCallback = function (){
console.log("success");
alert("success");
};
var failureCallback = function (){
console.log("failure");
alert("failure");
};
pedometer.startPedometerUpdates(successHandler, onError);
//pedometer.stopPedometerUpdates(successCallback, failureCallback);
pedometer.isDistanceAvailable(successCallback, failureCallback);
pedometer.isStepCountingAvailable(successCallback, failureCallback);
}
app.initialize();
isDistanceAvailable, isStepCountingAvailable both returns success.
I ma testing it on Xiaomi redmi 3 with Android Lolipop 5.0.
Thanks for any help.