So this whole new android runtime permissions has gotten me confused. My app is currently compiling and targetting version 23 which means I have to use runtime permissions. My app primarily uses the camera api which needs the camera permission so I added the runtime permissions before opening the camera as such:
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED)
{//ask permissions for camera
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA},
CameraPermissions);
}
else
{//permissions attained now you can open the camera
camera=Camera.open(getCid());
camera.setPreviewCallback(this);
initPreview(width, height);
startPreview();
startTimer();
}
I also check when I stop the camera:
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED) {
camera.setPreviewCallback(null);
camera.release();
faceProc.release();
faceProc = null;
camera = null;
inPreview = false;
cameraConfigured = false;
}
The permission request is handled as such:
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case CameraPermissions: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
StartUpCam();
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("How is this app going to work if you rejected the camera permission.... DUHHHH!!")
.setTitle("Rejected");
builder.setPositiveButton("Exit App", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//close application
closeApp();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
return;
}
}
}
So when the request is given it calls the StartUpCam which then tries to open the camera if the permissions is given. So here comes my questions, if I add this runtime permission checks how does this affect android devices lower than 6.0?? So a phone with version 5.0.1 will also get a prompt to give camera permissions? If I use runtime permissions, do I have to remove the camera permissions in the manifest file? Currently, I keep the camera permissions in the manifest along with the runtime permissions I don't know if that is correct or not. What if I lower the target and compiling sdk to 22 instead of 23, will android devices above 6.0 won't be able to download my app??? If I lower it to version 22 then I avoid all this headache...