Android10 calls the camera (involving reading and writing files) flashback

background

According to << the first line of Android code>>, I wrote a case of calling the camera and photo album. The page looks like the screenshot below. After taking a photo or selecting a picture from the photo album, the picture will be displayed in the imageView below.

When clicking the "Choose photo from album" button, the function is normal, but when clicking the "Take photo" button, it will flash back and report that the camera is abnormal.

Please add a picture description

Solution

It is not mentioned in the book (maybe it is a version problem, I read the third edition, based on Android10) to configure read and write permissions separately, so when the project is running, it keeps crashing.

Later, I found out that if the permission is added, it will not flash back. It is estimated that the file object is created in the program to store the pictures after taking pictures. This place involves storage read and write permissions, so additional configuration is required.

	<!--外部存储的写权限-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!--外部存储的读权限-->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Guess you like

Origin blog.csdn.net/Charonmomo/article/details/131921009