Take A Photo in Android Phone- App Dev Series 6
Objective: using Android device camera to take a photo in app.
As a modern app in many usage, having photo taking function is quite reasonable.
Today’s article we will create a function to our app that make the device(android) is able to take a photo in App via its camera.
According to the update log in Github, you can use it directly after imported.
With plugin imported(installed), we can use the code example from Github.
This method is exactly showing how to use this taking photo function. We can copy this part of code and paste it to our script.
If there is no error appear on your code, then you are successfully imported the plugin without any error.
Press a button to take photo
In my app as example, I would like to enable the camera once I press the taking photo icon on my app. Then showing the photo on an raw image UI element after shot.
First we need to get the reference of raw image in script, which would be replaced the texture with taken photo.
Then paste in the code we copied from Github.
Inside this method, we need to remove the part that created a quad to storage the photo. Instead, we need to make the taken photo as a texture to replace the origin one from raw image.
Then create a public method to be called from a button click, to enable the camera function.
Then assign this method to the button, and everything would be done!
You can build this app to check the result!