美文网首页
工具类——跳转到定位服务设置界面

工具类——跳转到定位服务设置界面

作者: 楷桐 | 来源:发表于2018-09-11 11:41 被阅读31次
    private LocationManager lm;
        lm = (LocationManager) getSystemService(LOCATION_SERVICE);
        boolean ok = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (ok) {//开了定位服务
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                    != PackageManager.PERMISSION_GRANTED) {
                // 没有权限,申请权限。
                Toast.makeText(this, "没有权限", Toast.LENGTH_SHORT).show();

            } else {
                // 有权限了,去放肆吧。
                Toast.makeText(this, "有权限", Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(this, "系统检测到未开启GPS定位服务", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent();
            intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivityForResult(intent, 1315);
        }
    

相关文章

网友评论

      本文标题:工具类——跳转到定位服务设置界面

      本文链接:https://www.haomeiwen.com/subject/mvaygftx.html