Function onSuccess doesn't fire event on android

Hey

this doesn’t work on my android device (Android 5.0 / EMUI 3.1)
The alert does not pop up, or anything else in the onSuccess function.

Anyone knows why?

.controller('DiagWinkelACtrl', function($scope) {

$scope.myDeg = 90;

// READY
document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
function onDeviceReady() {
    navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
}

// onSuccess: Get a snapshot of the current acceleration
function onSuccess(acceleration) {
    alert('Acceleration X: ' + acceleration.x + '\n' +
          'Acceleration Y: ' + acceleration.y + '\n' +
          'Acceleration Z: ' + acceleration.z + '\n' +
          'Timestamp: '      + acceleration.timestamp + '\n');
}

// onError: Failed to get the acceleration
function onError() {
    alert('onError!');
}

})

the problem is, that it could be possible that you put the eventlister on the document, after the event is triggered.

Try to use:

ionic.Platform.ready(function(){
  // will execute when device is ready, or immediately if the device is already ready.
});

http://ionicframework.com/docs/api/utility/ionic.Platform/

Still I can’t get it to run a simple alert inside the onSuccess function… I tried so many things.
Could you provide me a full example with the ionic.Platform.ready function?

Hi! Did you find a way to solve the issue? I’m afraid I’m having the same one!
Thank you in advance.
Adrian

Nope, not really… sorry.

in my cases i do not see any alerts on android… maybe they are supressed. try a console log if it is executed.