Prevent GPS Spoofing

Posted By : Sapna Sharma | 19-May-2016

Before going to develop a location based app, it’s important to know that hackers can spoof their GPS location and illegally activate our app’s features.

As we know in Android system resources are shared across its applications. This is the basic difference from iOS environment where every app gets its own sandbox environment. So we need to take some extra measures.

To prevent our location based app from getting spoofed, we can check whether the location is coming from real provider or from a test/fake provider so that we can filter out fake locations.

 

With the below code we can check if the device enables Mock Locations and might be using a fake GPS app:

 
 public boolean isMockLocationEnabled(Context context) { 
  if (Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0")) 
    return false; 
  else 
    return true; 
}

 

Since API 18, the object Location has the method .isFromMockProvider() so If you want to support versions before 18, it is possible to use something like this:
 
//returns true if mock location enabled, false if not enabled
boolean isMock = false;
if (android.os.Build.VERSION.SDK_INT < 18) {
  if (Settings.Secure.getString(currentActivity.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
     isMock = false;
  else
     isMock = true;
} else {
  isMock = location.isFromMockProvider();
}

 

 

Thanks

About Author

Author Image
Sapna Sharma

Sapna is a bright Android Apps developer using Titanium framework. Sapna likes music and helping needy people.

Request for Proposal

Name is required

Comment is required

Sending message..