You have to manage run time permission for this, Because whichever permissions you have defined in AndroidManifest will not be automatically granted. So like below method you can check whether you permission is approved or not
if (checkSelfPermission(Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA},
MY_REQUEST_CODE);
}
Here, MY_REQUEST_CODE is a static constant that you can define, which will be used again for the requestPermission dialog callback. Now, You will need a callback for the dialog result:
@Override
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == MY_REQUEST__CODE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Now user should be able to use camera
}
else {
// Your app will not have this permission. Turn off all functions
// that require this permission or it will force close like your
// original question
}
}
}