Settings.Secure.ALLOW_MOCK_LOCATION始终返回1,即使模拟设置为关闭

Jef*_*eff 4 gps android location

我正在开发一个应用程序,如果使用这段代码启用模拟位置设置,用户将无法使用它

if (Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
        return false;
    else
        return true;
Run Code Online (Sandbox Code Playgroud)

好吧,它在我从KitKat到Marshmallow系统的大多数测试设备上运行良好,直到我在使用Marshmallow OS的这个设备上尝试我的应用程序,模拟设置显然是OFF,但上面的代码一直告诉我模拟设置为ON这是一个错误吗?还是我错过了什么?

Non*_*hoi 7

这里查看这个答案.

boolean isMock = false;
if (android.os.Build.VERSION.SDK_INT >= 18) {
    isMock = location.isFromMockProvider();
} else {
    isMock = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
}
Run Code Online (Sandbox Code Playgroud)

这可能对你有帮助