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.

Import plugin

This function requires a plugin developed by yasirkula, which can be downloaded from Assets Store of Unity or Github.
Once downloaded it, drag the Plugin folder into Assets of your project.

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.

Don’t for get to set a maximum photo size as parameter.

Then assign this method to the button, and everything would be done!
You can build this app to check the result!

--

--

--

A passionate gamer whose goal is to work in video game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Android Jetpack a Promise to Accelerate App Development

Medium you need to sort out the Mess of linking articles for Android users

ConstraintLayout 2.0.2 performance

Dialog in Android Jetpack Compose with MVVM

Collapsing Toolbar in Jetpack Compose | ‘LazyColumn’ version — Part 2

final Button mybutton = new Button(ProjectinActivity.this);

Using Dagger-Android in a multi-module project

Coordinator Layout with Xamarin.Forms

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Mobile Game Progression

How to Add a Custom Skybox

New Input System and UI

Level Design in Unity Part 2: The Walls