Android检测GPS服务和定位权限是否开启

栏目: IOS · Android · 发布时间: 7年前

内容简介:判断是否开定位权限,没开并跳转权限界面

判断是否开定位权限,没开并跳转权限界面

private LocationManager lm;//【位置管理】
lm = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE);
boolean enable = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (enable) {//开了定位服务
    if (ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// 没有权限,申请权限。
//                        Toast.makeText(getActivity(), "没有权限", Toast.LENGTH_SHORT).show();

    } else {
// 有权限 do something
//                        Toast.makeText(getActivity(), "有权限", Toast.LENGTH_SHORT).show();
    }
    } else {
    Toast.makeText(getActivity(), "系统检测到未开启GPS定位服务", Toast.LENGTH_SHORT).show();
// 跳转到开启页面
    Intent intent = new Intent();
    intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    startActivityForResult(intent, 200);
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

The Algorithmic Beauty of Plants

The Algorithmic Beauty of Plants

Przemyslaw Prusinkiewicz、Aristid Lindenmayer / Springer / 1996-4-18 / USD 99.00

Now available in an affordable softcover edition, this classic in Springer's acclaimed Virtual Laboratory series is the first comprehensive account of the computer simulation of plant development. 150......一起来看看 《The Algorithmic Beauty of Plants》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

随机密码生成器
随机密码生成器

多种字符组合密码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具