[Development] Does QGeoPositionInfoSource work from an Android service?

Ryan Chu Ryan.Chu at qt.io
Thu Oct 25 08:31:03 CEST 2018


Hi Denis,


> but a service, seems, crashed at all (at least I did not see any debugging log from the logcat).


Regarding to the "crashed symptom", have you checked the value of 'ps' before setting setUpdateInterval?


(Qt Docs - QGeoPositionInfoSource::createDefaultSource)

"Returns 0 if the system has no default position source, no valid plugins could be found or the user does not have the permission to access the current position."


Best regards,

Ryan


________________________________
From: Development <development-bounces+ryan.chu=qt.io at qt-project.org> on behalf of Denis Shienkov <denis.shienkov at gmail.com>
Sent: Wednesday, October 24, 2018 6:31 PM
To: development at qt-project.org; Alex Blasche; BogDan Vatra
Subject: [Development] Does QGeoPositionInfoSource work from an Android service?

Hi all,

I tried to make it work from the Android service:


#include <QAndroidService>

#include <QGeoPositionInfoSource>

#include <QLoggingCategory>

#include <QTimer>


Q_LOGGING_CATEGORY(APP, "bug.svc")


int main(int argc, char *argv[])

{

    QAndroidService::setAttribute(Qt::AA_EnableHighDpiScaling);

    QAndroidService app(argc, argv);


    qCDebug(APP) << "I'm service";


    const auto t = new QTimer(qApp);

    QCoreApplication::connect(t, &QTimer::timeout, []() {

        static int counter = 0;

        qCWarning(APP) << "CNT:" << counter;

        ++counter;

    });

    t->start(1000);


    const auto ps = QGeoPositionInfoSource::createDefaultSource(qApp);

    QCoreApplication::connect(ps, &QGeoPositionInfoSource::positionUpdated,

                              [=](const QGeoPositionInfo &update) {

        const auto coord = update.coordinate();

        qCDebug(APP) << "CRD:" << coord;

    });

    ps->setUpdateInterval(3000);

    ps->startUpdates();


    return app.exec();

}

but a service, seems, crashed at all (at least I did not see any debugging log from the logcat).

But if I try to cemment out all code, related to the locations, and keep a code with the timer,
then I see the counters output.

I tried it on Android x86 && Qt 5.11.2 && Android API 21.

E.g. from here: https://stackoverflow.com/questions/13345002/locationmanager-in-service
[https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/13345002/locationmanager-in-service>

android - LocationManager in service - Stack Overflow<https://stackoverflow.com/questions/13345002/locationmanager-in-service>
stackoverflow.com
Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site ...


I see that it is possible to wotk with Android's LocationManager from the service... BUT,
it does not work with QGeoPositionInfoSource!

BR,
Denis




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20181025/86821317/attachment.html>


More information about the Development mailing list