O
O
OM12016-09-08 08:59:00
satellite navigation
OM1, 2016-09-08 08:59:00

Android: how to implement gps location via BroadcastReceiver?

Good afternoon!
Is it correct approach to take coordinates through BroadcastReceiver?
Or is it like extra. method for determining geodata?
How to use this receiver:

protected BroadcastReceiver singleUpdateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            context.unregisterReceiver(singleUpdateReceiver);

            String key = LocationManager.KEY_LOCATION_CHANGED;
            Location location = (Location)intent.getExtras().get(key);

            Toast.makeText(getApplicationContext(), "BroadcastReceiver: "+Double.toString(location.getLatitude()), Toast.LENGTH_LONG).show();
        }
    };

Is it just to register in the manifest or do I still need to process events in the activity?
And another question on the topic:
getLastKnownLocation gives out only the already available data received before. How to use this method to get up-to-date data at the moment?
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question