如何检查模拟定位在Android的棉花糖? [英] How to check for Mock Location in Android Marshmallow?

查看:1076
本文介绍了如何检查模拟定位在Android的棉花糖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测,如果该位置被触发与模拟位置 Android中棉花糖

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

previously,我用 Settings.Secure.ALLOW_MOCK_LOCATION

Previously, I used Settings.Secure.ALLOW_MOCK_LOCATION

但是,在API级别23,这一直是德precated。

But, in API level 23, this has been deprecated.

我要检查,如果触发是假的位置,或者原来的GPS?

I want to check if the trigger is with Fake location or original GPS ?

现在,什么是替代检查模拟位置已启用 Android的棉花糖

Now, what is the alternative to check if Mock Location is enabled or not Android Marshmallow?

推荐答案

如果您使用的是 FusedLocationProviderApi ,并建立使用 setMockLocation模拟位置(mGoogleApiClient ,fakeLocation); 回调/ pendingIntentCallback返回位置对象包含 KEY_MOCK_LOCATION 额外的,一个布尔值,表示接收对象是模拟。

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);

}

这篇关于如何检查模拟定位在Android的棉花糖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆