1,刚出现这样的问题我是直接把 CAMERA 移除掉
2.第一步判断时候授权。
if (Build.VERSION.SDK_INT >= 23) { int checkCallPhonePermission = ContextCompat.checkSelfPermission(AppointmentDetailActivity.this, Manifest.permission.CAMERA); if(checkCallPhonePermission != PackageManager.PERMISSION_GRANTED){ ActivityCompat.requestPermissions(AppointmentDetailActivity.this,new String[]{Manifest.permission.CAMERA},OPEN_CANMER); return; }else{ showCamera(); } } else { showCamera(); }
第二步 接收返回的结果。
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case OPEN_CANMER: if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { showCamera(); } else { Toast.makeText(AppointmentDetailActivity.this, "相机权限禁用了。请务必开启相机权", Toast.LENGTH_SHORT).show(); } break; default: super.onRequestPermissionsResult(requestCode, permissions, grantResults); } }