Running a service to get location details

前端 未结 3 1814
日久生厌
日久生厌 2021-02-11 02:25

In my app, i need to create an android service to periodically get mobile user\'s current location(latitude and longitude). The service should get user\'s location in every 5 mi

3条回答
  •  一整个雨季
    2021-02-11 03:12

    You can write a private/internal class(within your service) that implements locationListener and in the onStart meethod of your service you can requestLocationUpdates which will be listened by your listener

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    MyLocationListener listener = new MyLocationListener();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, listener);
    

提交回复
热议问题