Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Can not using the QAccelerometer in the android service

    Mobile and Embedded
    1
    1
    143
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mr_roman last edited by

      Good evening. Sorry for my bad english :-(
      For several days i cannot solve the problem with start QAccelerometer in the android background service.

      I am developing the android service as separate .so file.
      In the service i write the following code:
      in .h file:

          private: 
              QAccelerometer *m_sensor;
      

      in .cpp file (in the constructor class):

          GSensorClass::GSensorClass(QObject *parent) : QObject(parent)
          {
              m_sensor = new QAccelerometer(this);
              connect(m_sensor, SIGNAL(readingChanged()),
                          this, SLOT(onReadingChanged()));
              m_sensor->setAlwaysOn(true); 
              m_sensor->start();
          }
      

      Unfortunately, the method start returns false(( If i call m_sensor->error(), it returns 0 (zero).

      In the service and main application .pro file i added Qt += sensors.
      In AndroidManifest.xml of the main application i added:

          <uses-feature android:name="android.hardware.sensor.accelerometer" />
      

      If this code run under android GUI application, it works fine and i can access to x,y and z coordinates, but if this code run in the android service, then m_sensors->start(); returns false.

      Maybe I'm doing something wrong? I really hope, that this problem can be solved, using Qt.
      Please, help me.
      Thanks!

      1 Reply Last reply Reply Quote 0
      • First post
        Last post