How to check for Mock Location in Android Marshmallow?

后端 未结 4 1621
-上瘾入骨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:25

    This answer didn't seem to be work for me. extras.getBoolean(FusedLocationProviderApi.KEY_MOCK_LOCATION, false) always returned false.

    However, I did this:

    @Override
    public void onLocationChanged (Location location){
        boolean isMockLocation = location.isFromMockProvider();
    }
    

    and I started getting the correct results.

提交回复
热议问题