kivy / plyer

Plyer is a platform-independent Python wrapper for platform-dependent APIs
https://plyer.readthedocs.io
MIT License
1.61k stars 427 forks source link

Can plyer.gps work when the application is minimized or running in the background? #769

Closed killatonna1 closed 11 months ago

killatonna1 commented 1 year ago

Can plyer.gps work and collect data from the GPS module when the android application is minimized or running in the background? If possible, are there implementation examples.

My code only works when the application is active. But for example, the requests library continues to send data in a collapsed mode. Most likely my problem is either with permissions or with the implementation.

Can anybody help?

buildozer.spec permissions

android.permissions = android.permission.INTERNET, FOREGROUND_SERVICE_LOCATION, ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION, ACCESS_BACKGROUND_LOCATION

My code:

import time
from jnius import autoclass

PythonService = autoclass('org.kivy.android.PythonService')
PythonService.mService.setAutoRestartService(True)
from plyer import gps

def get_gps_data():
    gps.configure(on_location=on_location)
    gps.start(1000, 0) 

def on_location(**kwargs):
    latitude = kwargs.get('lat')
    longitude = kwargs.get('lon')
    print(f'coords: {latitude}, {longitude}')
if __name__ == '__main__':
    get_gps_data()
    try:
        while True:
            pass  
    except:
        print('service stop')
Julian-O commented 11 months ago

👋 Sorry to hear you are having difficulties; Kivy unites a number of different technologies, so developing apps can be temperamental.

We try to use GitHub issues only to track work for developers to do to fix bugs and add new features to this project. This issue is being closed, because it doesn't describe a bug in this project.

There is a mailing list and a Discord channel to support Kivy users debugging their own systems, which should be able to help. They are linked in the ReadMe.

Of course, if it turns out you have stumbled over a bug in this project, we do want to hear about it here. The support channels should be able to help you craft an appropriate bug report.