Android ble扫描版本高于6.0后需要定位权限

参考博客:http://blog.csdn.net/sun6223508/article/details/50505936


private  final int REQUEST_FINE_LOCATION = 1;

private void mayRequestLocation() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int cllPhonePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION);
        if (callPhonePermission != PackageManager.PERMISSION_GRANTED) {
          
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_COARSE_LOCATION))
                playToast(getString(R.string.ble_need));
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_FINE_LOCATION);
            return;
        }
    }
}


@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {
    switch (requestCode) {
        case REQUEST_FINE_LOCATION:
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                startScan();
            }
            break;
    }
}

阅读更多
上一篇Fragment切换动画
下一篇android 6.0 动态权限申请
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭