It’s not that easy to track the user location on Android

Alen Huskanović
Apr 9, 2017 · 3 min read
Image for post
Image for post
Source: Unsplash

As an Android developer I love my job, it’s exciting and challenging but sometimes it makes me going crazy.

Tracking application

On google play you can find whatever you want, Android is everywhere and it’s just waiting to take everything. Long story short, the market is crazy. There are apps that track your activities and guess what? I am working on one that does exactly that, tracks user’s movement.

It’s not a big deal, we have users that are doing some activities outside and to get shit done they have to use a car to go from place to place. Based on their mileage users get paid for the fuel. That is the reason why we track them and why it’s very important for us to know exactly where they were.

Houston, we have a problem

Everything was fine, we had the app that was doing the job, but we started to struggle with battery consumption. Our app is draining the battery faster than other apps and users started to complain about it.

Ok, we got it, the user is always right, we have to solve that.

Challenge accepted

We cannot leave it as it is, we need to find a better way to track the user’s location with less battery consumption. The first step is to review our process which is the problem.

How do we track the user

We don’t track every activity, we track the location of the user. Let’s explain it.

We have two services:

  • BreadcrumbService — this service is getting the user location every 30 sec if user moves more than 40 meters from last reading.
  • FusedProviderService — this service is getting the user location every 5 minutes if user moves more than 200 meters.

Depending on some permissions we will fire one of them, but in some combination, both of them will be running. Both of them are using fused provider for location. Also, we are using PRIORITY_HIGH_ACCURACY as a parameter.

The challenge

What is the challenge here? Well, we have two core problems here :)

Problem #1

Users should work in this environment for 8 hours. So, 8 hours we have to track the user’s location, we must have accuracy of at least 50. The battery on the phone could last more than 8 hours, but on devices with low power battery it will last just 6 hours.

Problem #2

Sometimes we have the problem with hyper jumps. That means that two locations that come one after another are totally different. It happens on some devices that have bad/cheap hardware and GPS module. We try to solve this by comparing last two locations and checking if there is too big of a difference. But, if the first location is wrong (if user is inside some building) and then gets out, we will conclude that the second (the right) location is wrong and that will make the wrong forward readings.

What we plan to do?

We want to make a new service ActivityRecognitionAPI to detect user activity. So, if user is walking or driving we will run the services, but if user (device) is on STILL mode we will turn them off and use last known location.

What is the question?

Do you have any advice on how to solve the problems mentioned above? Also, what do you think about the approach that we want to attack to solve those problems? I am not sure what will be the effect on battery when we make a new service that will track user activity.

If you faced similar problems and you know how to solve it or at least which way to go, shout the comment below and help this poor android brother :)

One last thing…

If you liked this article, click the💚 below so other people will see it here on Medium.

It Works Locally

Everyday problems, ideas and thoughts by a group of…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store