Android 6.0之后需要动态申请相机权限
首先得把申明的静态权限删除
然后申请动态权限
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CAMERA) != PackageManager
.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{Manifest.permission.CAMERA }, 1);
} else {
openCamera();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
switch (requestCode) {
case 1:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
openCamera();
} else {
Toast.makeText(this, "You denied the peimission",
Toast.LENGTH_SHORT).show();
}
break;
default:
}
}