Search code examples
androidcordovaionic-frameworkcordova-pluginssensors

cordova-plugin-device-motion Exception in start() method


I have a problem with the cordova plugin cordova-plugin-device-motion on my Android 5.1.1 Phone (Honor 6). Here is my code:

$scope.options = {
    frequency: 100, 
    deviation : 25  
};
$scope.startWatching = function() {
    $scope.watch = $cordovaDeviceMotion.watchAcceleration($scope.options);
    $scope.watch.then(null, function(error) {
        console.log('Error');
    },function(result) {
        //success callback
    });
};

Inside watchAcceleration(), the native start() method is called. I get valid results (the success callback gets called), but nevertheless I get the following logcat output:


06-09 12:32:13.634: I/SensorManagerFlow(6623): registerListenerImpl
06-09 12:32:13.634: I/SensorManagerFlow(6623): java.lang.Exception
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at android.hardware.SystemSensorManager.registerListenerImpl(SystemSensorManager.java:118)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at android.hardware.SensorManager.registerListener(SensorManager.java:775)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at android.hardware.SensorManager.registerListener(SensorManager.java:682)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at org.apache.cordova.devicemotion.AccelListener.start(AccelListener.java:157)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at org.apache.cordova.devicemotion.AccelListener.execute(AccelListener.java:107)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at org.apache.cordova.PluginManager.exec(PluginManager.java:133)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at android.os.Handler.dispatchMessage(Handler.java:102)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at android.os.Looper.loop(Looper.java:135)
06-09 12:32:13.634: I/SensorManagerFlow(6623):  at android.os.HandlerThread.run(HandlerThread.java:61)

Then I stop recording via:

$scope.watch.clearWatch();

and start it again:

$scope.startWatching();

I get the same error in logcat output again. But now also the success callback does not get called anymore.

Would be nice if anyone could help me why that happens :)

The error is very specific to my device. I tested it on another android 5.1.1 device, a android 6 device and on an Iphone. It works good on these devices. Here is a list of the most important features of my phone:

System
Device Model: Huawei Honor 6
Model: H60-L04
Installed RAM: 3 GB LPDDR3

CPU
SoC Model: HiSilicon Kirin 920
Core Architecture: 4x ARM Cortex-A7 @ 1305 MHz
4x ARM Cortex-A15 @ 1708 MHz
Instruction Set: 32-bit ARMv7
Supported ABIs: armeabi-v7a, armeabi
Supported 32-bit ABIs: armeabi-v7a, armeabi

Android
Android Version: 5.1.1 (Lollipop)
API Level: 22
Rooted Device: No
Kernel Architecture: armv7l
Kernel Version: 3.10.74-gc69e6c2
Google Play Services Version: 9.0.83 (238-121911109)

Sensors
LSM330 3-axis Accelerometer:
iNemo Linear Acceleration sensor:

Solution

  • After spending enough time to figure out the problem, all i could conclude is that this issue has got nothing to do with plugin.

    An Android version upgrade should fix the issue as it looks more of sensor issue than the actual application issue.