[Development] Does QGeoPositionInfoSource work from an Android service?
Denis Shienkov
denis.shienkov at gmail.com
Wed Oct 24 18:31:59 CEST 2018
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20181024/6d44de0a/attachment.html>
More information about the Development
mailing list