需要定位的时候就出现各种各样的问题。

解决了Android6.0动态权限申请的博客:这里主要是167错误,需要一个动态权限的申请。
参考博客:http://blog.csdn.net/jh1137921986/article/details/70225052
参考博客:http://blog.csdn.net/kjunchen/article/details/52769915

画线的博客:http://blog.csdn.net/JJ583500596/article/details/70261311?locationNum=10&fps=1

需要定位的时候会出现的一些错误码如下:我遇到的是167

public void setLocType(int var1) {
        this.mLocType = var1;
        switch(var1) {
        case 61:
            this.setLocTypeDescription("GPS location successful!");
            this.setUserIndoorState(0);
            break;
        case 62:
            this.setLocTypeDescription("Location failed beacuse we can not get any loc information!");
            break;
        case 63:
        case 67:
            this.setLocTypeDescription("Offline location failed , please check the net (wifi/cell)!");
            break;
        case 66:
            this.setLocTypeDescription("Offline location successful!");
            break;
        case 161:
            this.setLocTypeDescription("NetWork location successful!");
            break;
        case 162:
            this.setLocTypeDescription("NetWork location failed because baidu location service can not decrypt the request query, please check the so file !");
            break;
        case 167:
            this.setLocTypeDescription("NetWork location failed because baidu location service can not caculate the location!");
            break;
        case 505:
            this.setLocTypeDescription("NetWork location failed because baidu location service check the key is unlegal, please check the key in AndroidManifest.xml !");
            break;
        default:
            this.setLocTypeDescription("UnKnown!");
        }

    }

所谓的动态权限的申请是指,Android6.0中,引入了动态申请权限机制。 以前我们在申请权限的时候,都是写在了Manifest.xml里面。 安装的时候会有一堆提示申请权限的界面, Google 可能想到用户可能并不注意这些权限。所以就迎来了 动态权限机制。
参考博客:http://blog.csdn.net/xuezhe__/article/details/51541553

我的动态申请的代码:

private static final int REQUEST_CODE_ACCESS_COARSE_LOCATION = 1;

 @TargetApi(Build.VERSION_CODES.M)
    private void requestPermission() {
        //Android 6.0判断用户是否授予定位权限
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//如果 API level 是大于等于 23(Android 6.0) 时
            //判断是否具有权限
            if (ContextCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                //判断是否需要向用户解释为什么需要申请该权限
                if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                        Manifest.permission.ACCESS_COARSE_LOCATION)) {
                    Toast.makeText(MainActivity.this,"自Android 6.0开始需要打开位置权限",Toast.LENGTH_SHORT).show();
                }
                //请求权限
                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                        REQUEST_CODE_ACCESS_COARSE_LOCATION);
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == REQUEST_CODE_ACCESS_COARSE_LOCATION) {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                //用户允许改权限,0表示允许,-1表示拒绝 PERMISSION_GRANTED = 0, PERMISSION_DENIED = -1
                //permission was granted, yay! Do the contacts-related task you need to do.
                //这里进行授权被允许的处理
            } else {
                //permission denied, boo! Disable the functionality that depends on this permission.
                //这里进行权限被拒绝的处理
            }
        } else {
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐