Android的检测位置设置 [英] Android detect location settings

查看:146
本文介绍了Android的检测位置设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的应用程序的新的位置API,我想知道如何,如果我的用户有手机上启用位置访问权限检测。

I'm using the new Location API in my app and I'm wondering how to detect if I the user has location access enabled on there phone.

我设立一个LocationClient和运行LocationRequest。我将如何运行检查在此之前,看看我是否能真正得到用户的位置?

I'm setting up a LocationClient and running a LocationRequest. How would I run a check before doing this to see if I can actually get the users location?

推荐答案

在您的onConnected你可以调用这样的方法:

In your onConnected you could call a method like these:

private boolean checkLocationProviders()
{
    if(mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
    {
        return true;
    }
    else
    {
        if(mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            return true;
        else
            return false;
    }
}

如果返回false时,你可以用这种方式打开设置界面:

If false is returned, you can open the Settings screen in this way:

startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

这篇关于Android的检测位置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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