From the Android Docs:
Beginning in Android 6.0 (API level 23), users grant permissions to
apps while the app is running, not when they install the app.
It means that on Android 23 or above, besides the manifest, you need to request permission on runtime as well. In this case, camera access.
To do this, you can use the code below:
// First check android version
if (MyVersion > Build.VERSION_CODES.LOLLIPOP_MR1) {
//Check if permission is already granted
//thisActivity is your activity. (e.g.: MainActivity.this)
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
// Give first an explanation, if needed.
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.CAMERA)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.CAMERA},
1);
}
}
}
You can also handle the request response, as described on the docs.
Hope it helps!