How to check for Mock Location in Android Marshmallow?

后端 未结 4 1633
-上瘾入骨i
-上瘾入骨i 2020-12-15 11:00

How to detect if the location is triggered with Mock Location in Android Marshmallow?

Previously, I used Settings.Secure.ALLOW_MOCK_L

4条回答
  •  忘掉有多难
    2020-12-15 11:45

    If you are using FusedLocationProviderApi and have set mock location using setMockLocation(mGoogleApiClient, fakeLocation); in the callback/pendingIntentCallback the returned Location object contains KEY_MOCK_LOCATION extra, a boolean that indicates that received object is mock.

    @Override
    
    public void onLocationChanged (Location location){    
       Bundle extras = location.getExtras();
       boolean isMockLocation = extras != null && extras.getBoolean(FusedLocationProviderApi.KEY_MOCK_LOCATION, false);
    
    }
    

提交回复
热议问题