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

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

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

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

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);
}

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

查看所有标签

猜你喜欢:

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

An Introduction to Probability Theory and Its Applications

An Introduction to Probability Theory and Its Applications

William Feller / Wiley / 1991-1-1 / USD 120.00

Major changes in this edition include the substitution of probabilistic arguments for combinatorial artifices, and the addition of new sections on branching processes, Markov chains, and the De Moivre......一起来看看 《An Introduction to Probability Theory and Its Applications》 这本书的介绍吧!

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

多种字符组合密码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器