我如何检查在应用GPS的支持,添加新功能对于那些位置服务启用? [英] How can I check for GPS support in-App to add a feature for those with Location services enabled?

查看:123
本文介绍了我如何检查在应用GPS的支持,添加新功能对于那些位置服务启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查支持GPS在应用中添加了一个功能,那些定位服务启用?

How can I check for GPS support in-App to add a feature for those with Location services enabled?

我关心的是,我知道我必须在清单中指定的标签声明,该应用程序使用位置服务,但我还是希望应用程序为那些没有工作。我只是想检查,如果该服务是可用的,使用它;否则就忽略这个功能。

My concern is, I know I'd have to specify the tag in the manifest to declare that the app uses location services, but I still want the app to function for those without. I just want to check and, if the service is available, use it; otherwise just ignore that one feature.

感谢。

推荐答案

您可以检查是否有位置服务通过查找,看是否有位置提供商都已启用。我用我的code这个功能现在:

You can check if any Location services are enabled by looking to see if any location providers are enabled. I'm using this function in my code right now:

public static boolean areProvidersEnabled(Context context) {
    ContentResolver cr = context.getContentResolver();
    String providersAllowed = Settings.Secure.getString(cr, Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    return providersAllowed != null && providersAllowed.length() > 0;
}

另一个美妙的事情是,你可以直接将用户的位置设置,并问他们是否要启用它。我将它留给你如何询问用户,但目的去的设置是这样的:

Another neat thing is that you can send the user straight to the Location settings and ask them if they want to enable it. I'll leave it to you on how to ask the user, but the Intent to get to the settings is like this:

Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(intent);

这篇关于我如何检查在应用GPS的支持,添加新功能对于那些位置服务启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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