如何以编程方式检查Android和QUOT;位置同意和QUOT ;? [英] How to programmatically check Android "Location Consent"?

查看:214
本文介绍了如何以编程方式检查Android和QUOT;位置同意和QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式确定用户是否同意或不同意,当你打开你的您的GPS在Android设备上出现的位置同意对话框。

I would like to programmatically determine whether the user has agreed or disagreed to the "Location Consent" dialog that appears when you turn your on your GPS on Android devices.

我一直没能找到从哪里得到这个信息,我不知道是否它的的实际可用内code?

I have not been able to find where to get this information from, and I'm not sure whether it is actually available anywhere within the code?

谢谢!

推荐答案

这是关于位置的模式。如果用户同意位置同意,位置模式高精度设置的。

This is about location mode. if the user agreed to the "Location Consent", location mode set on High Accuracy.

有关检查此模式下可以使用以下code:

For check this mode you can use following code:

    public static boolean checkLocationSettings(Context context) {

    int locationMode = 0;
    String locationProviders;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
        try {
            locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);

        } catch (SettingNotFoundException e) {
            e.printStackTrace();
        }

        return (locationMode != Settings.Secure.LOCATION_MODE_OFF && locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY); //check location mode

    }else{
        locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        return !TextUtils.isEmpty(locationProviders);
    }


}

这篇关于如何以编程方式检查Android和QUOT;位置同意和QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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