Android 6.0的权限问题
Android 6.0的权限获取不同于别的版本,具体的实例如下:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { //申请READ_CONTACTS权限 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS}, READ_CONTACTS_REQUEST_CODE); } @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); doNext(requestCode, grantResults); } private void doNext(int requestCode, int[] grantResults) { if (requestCode == READ_CONTACTS_REQUEST_CODE) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Permission Granted LogUtils.i(TAG,"获取了读取通讯录的权限"); creditCheckTask.getAndSendContact(); } else { LogUtils.i(TAG,"没有获取读取通讯录权限"); // Permission Denied return; } } }
大道至简,逻辑起点,记忆关联,直观抽象。。。