getScanResults一直为空的解决办法

    
    
    
    

 

 

    /*
 *判断当前是否是6.0版本
 */
    @TargetApi(23)
    private void getPersimmions() {
        判断当前是否是6.0版本
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            ArrayList permissions = new ArrayList();
            /***
             * 定位权限为必须权限,用户如果禁止,则每次进入都会申请
             */
            // 定位精确位置
            if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);

            }
            if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);

            }
            if (permissions.size() > 0) {
                requestPermissions(permissions.toArray(new String[permissions.size()]), PERMISSON_REQUESTCODE);
            } else {//****这里写自己的定位调用***/
                ///当权限都有时,开始定位
            }

        } else {

        }

    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == PERMISSON_REQUESTCODE) {
            //            Settings.Secure.putInt(getContentResolver(), Settings.Secure.LOCATION_MODE, 1);
            // 转到手机设置界面,用户设置GPS
//            Intent intent = new Intent(
//                    Settings.ACTION_LOCATION_SOURCE_SETTINGS);
//            startActivityForResult(intent, 0); // 设置完成后返回到原来的界面
        }
    }

 

 

你可能感兴趣的:(Android)