Talking about the statement of Android camera authority
- 2021-10-13 08:31:25
- OfStack
Recently, I wrote a project and found that after declaring the right to call the camera in AndroidManifest. xml, I couldn't start the camera by opening app. After a search, I found that:
The problem is that when the version of API used to write the project is too high (for example, the tester I used is android 5.0, while the API I used to write this project is 27, that is, android 7.0), APP cannot automatically request the hardware call permission from the system.
Solution:
After activity initializes the layout, add the following code:
setContentView(R.layout.activity_camera);
// Affirm 1 Permissions
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, CAMERA_JAVA_REQUEST_CODE);
}