I am trying to detect mock locations with the following code
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
On android 4.1 the sub isMockLocationOn returns me True if the option is enable in android settings but the Fake GPS provider is not running (not a big problem though)
The most problematic thing is that on android 7.1, the sub isMockLocationOn returns me always False even if a Fake GPS provider is running.
Where i am wrong?
Should i pass to the sub another type of Location object? how?
Is there a way to know if in the settings there is a Fake GPS provider configured (even if it is not running)?
Thanks in advance for help!
			
			
			
				B4X:
			
		
		
		Sub Process_Globals
   Dim JavaObject2 As JavaObject
   Dim CheckThis As Location
End Sub
Sub Service_Create
  JavaObject2.InitializeContext
  CheckThis.Initialize
End Sub
Sub Service_Start (StartingIntent As Intent)
   CheckThis.Latitude=Latitude 'Obtained by EsLocation2 lib
   CheckThis.Longitude=Longitude 'Obtained by EsLocation2 lib
Dim isFake As Boolean = JavaObject2.RunMethod("isMockLocationOn", Array(CheckThis))
End Sub
#If JAVA
//import android.app.Service;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.test.mock.MockContext;
import android.location.Location;
public boolean isMockLocationOn(Location location) {
Context context=this;
   boolean isMock = false;
    if (android.os.Build.VERSION.SDK_INT >= 18) {
        isMock = location.isFromMockProvider();
        return isMock;
    } else {
        if (Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
            return false;
        else {
            return true;
        }
    } 
}
#End IfOn android 4.1 the sub isMockLocationOn returns me True if the option is enable in android settings but the Fake GPS provider is not running (not a big problem though)
The most problematic thing is that on android 7.1, the sub isMockLocationOn returns me always False even if a Fake GPS provider is running.
Where i am wrong?
Should i pass to the sub another type of Location object? how?
Is there a way to know if in the settings there is a Fake GPS provider configured (even if it is not running)?
Thanks in advance for help!
 
				 
 
		 
 
		 
 
		 
 
		