Android reads the local gallery and calls the camera to shoot
This article mainly introduces how to read the pictures of Android local gallery and call Android camera for shooting.
1、 Layout
The layout is relatively simple. The layout file of mainactiivty has only two buttons, one is to read the gallery, the other is to open the camera, and the layout of resultactivity has only one ImageView, which is used to display the selected picture or the taken picture.
2、 Read Gallery
Since we need to open the gallery provided by Android, we need to use the intent class, which is mainly used for communication between different activities. The code is as follows:
3、 Take photos with camera
4、 Set callback method
It can be seen from the codes in 2 and 3 that since the startactivityforresult() method is run, we set a callback method to obtain the data selected in other applications:
5、 Show pictures
Displaying pictures is relatively simple. Get the path in intent in the new activity, then create a bitmap and set it to ImageView. The code is as follows:
So far, a demo of reading the local gallery and calling the camera has been completed.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.