I am learning how to request permissions. now i want to use the Camera hardware, and i am trying to request this permission. I referred to the official website of Android developers, and i used the example posted on the website but i changed it a little as i need to request Android Camera hardware.
the manifest file does not contain any permissions and I expect when i run the below posted code, the "Toast" will show up as there is no permissions added in the manifest file. but what happened is, when i run the App it does not ask for adding any permission nor the "Toast" appears.
please explain to me why that is happeneing and how to set it right
code:
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
Toast.makeText(this, "permission is not in the manifest file", Toast.LENGTH_SHORT).show();
}
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, MY_PERMISSIONS_REQUEST_CAMERA);
}