Course Content

Course Content

Developing Camera Application

Creating Camera Application

 

In this video we are going to create Camera application in Android.

First of all we will design the layout of our application, for that we will open activity_main.xml file and imside that we will take one Relative Layout, Button, and an ImageView.

Now we will see the Java code of this application in MainActivity.java file,

public class MainActivity extends Activity

{

private static final int CAMERA_REQUEST=1888;

ImageView imageView;

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

imageView=(ImageView)this.findViewById(R.id.imageView1);

Button photoButton=(Button)this.findViewById(R.id.button1);

photoButton.setOncliclListener(()

{

Intent cameraIntent=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(cameraIntent,CAMERA REQUEST);

}};

protected void onActivityResult(int requestCode, int resultCode, Intent data)

{

if(requestedCode==CAMERA_REQUEST)

{

Bitmap photo=(Bitmap)data.getExtras().get("data");

imageView.setImageBitmap(photo);

Now we will execute our code, and we need to run this application in a real device, not emulator. So for that we will connect one device and use it to run our code. As soon as we run our code, it executes properly. Camera captures image first and then show it's preview to us.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
App Store
397K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
13K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere