如何在Android的M键选定读取模拟位置的应用程序 - 23 API [英] How to read selected mock location app in Android M - API 23

查看:833
本文介绍了如何在Android的M键选定读取模拟位置的应用程序 - 23 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到阅读的新设置在版本的Andr​​oid M模拟地点的方式。

I am trying to find a way of reading the new settings for mock locations in Android M.

在Android的男,模拟位置设置被称为使用模拟地点一个切换选项,这是可读使用此设置: Settings.Secure.ALLOW_MOCK_LOCATION

Before Android M, the mock location setting was a toggle option called "use mock locations", and it was readable with this setting: Settings.Secure.ALLOW_MOCK_LOCATION

使用Android的男,模拟位置设置是一个应用程序来选择模拟地点,所以它是一个多元素的列表,该列表中选择元素可以是无。

With Android M, the mock location setting is an app to select for mock locations, so it is a multi-elements list, which selected element can be "none".

这线程都有聆听位置时,确定位置更新源的解决方案,但不幸的是我想读设置本身:
<一href=\"http://stackoverflow.com/questions/32668494/how-to-check-for-mock-location-in-android-marshmellow\">How来检查的Andr​​oid MARSHMELLOW模拟位置?

That thread has a solution for determining the source of the location update when listening for locations, but unfortunately I would like to read the setting itself: How to check for Mock Location in Android Marshmellow?

我想读是否有选择的应用程序进行模拟地点与否,最好选择的应用程序也是如此。任何想法如何做到这一点的欢迎!

I would like to read whether there is a selected app for mock locations or not, and ideally the selected app as well. Any idea about how to do that are welcome!

推荐答案

好吧通过Android开发者网站挖这就是我想出。你必须使用 AppOpsManager checkOp(机器人:mock_location,yourUID,com.your.package.name)

Ok digging through the android developer site this is what I have come up with. You have to use the AppOpsManager. checkOp("android:mock_location", "yourUID", "com.your.package.name")

我觉得你可以检查是否有不同的应用程序是通过改变包名启用。

I think you can check if a different app is enabled by changing the package name.

public boolean isMockLocationEnabled()
{
    boolean isMockLocation = false;
    try
    {
        //if marshmallow
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        {
            AppOpsManager opsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
            isMockLocation = (opsManager.checkOp(AppOpsManager.OPSTR_MOCK_LOCATION, android.os.Process.myUid(), BuildConfig.APPLICATION_ID)== AppOpsManager.MODE_ALLOWED);
        }
        else
        {
            // in marshmallow this will always return true
            isMockLocation = !android.provider.Settings.Secure.getString(mContext.getContentResolver(), "mock_location").equals("0");
        }
    }
    catch (Exception e)
    {
        return isMockLocation;
    }

    return isMockLocation;
}

这篇关于如何在Android的M键选定读取模拟位置的应用程序 - 23 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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