Discussion:
[Development] Does QGeoPositionInfoSource work from an Android service?
Denis Shienkov
2018-10-24 16:31:59 UTC
Permalink
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
I see that it is possible to wotk with Android's LocationManager from the
service... BUT,
it does not work with QGeoPositionInfoSource!

BR,
Denis
Ryan Chu
2018-10-25 06:31:03 UTC
Permalink
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-project.org> on behalf of Denis Shienkov <***@gmail.com>
Sent: Wednesday, October 24, 2018 6:31 PM
To: ***@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
[Loading Image...

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
Alex Blasche
2018-10-25 06:42:18 UTC
Permalink
Hi Denis,

At least in the past it worked as I remember having tested the use case. Do you have a backtrace?

And yes, Ryan's comment is correct in that you are missing essential error checking in your code.

--
Alex

________________________________________
From: Denis Shienkov <***@gmail.com>
Sent: Wednesday, 24 October 2018 6:31:59 PM
To: ***@qt-project.org; Alex Blasche; BogDan Vatra
Subject: 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
I see that it is possible to wotk with Android's LocationManager from the service... BUT,
it does not work with QGeoPositionInfoSource!

BR,
Denis
Denis Shienkov
2018-10-25 09:30:22 UTC
Permalink
Alex,

I have created a bug: https://bugreports.qt.io/browse/QTBUG-71396
Please look on...

Denis
Post by Ryan Chu
Hi Denis,
At least in the past it worked as I remember having tested the use case.
Do you have a backtrace?
And yes, Ryan's comment is correct in that you are missing essential error
checking in your code.
--
Alex
________________________________________
Sent: Wednesday, 24 October 2018 6:31:59 PM
Subject: Does QGeoPositionInfoSource work from an Android service?
Hi all,
#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.
https://stackoverflow.com/questions/13345002/locationmanager-in-service
I see that it is possible to wotk with Android's LocationManager from the service... BUT,
it does not work with QGeoPositionInfoSource!
BR,
Denis
_______________________________________________
Development mailing list
http://lists.qt-project.org/mailman/listinfo/development
Loading...