Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Camera In Android Studio

Welcome to EasyCoding with Ammara
Subscribe My Coding Channel:
https://www.youtube.com/channel/UC8UsfNYmbKiRJvI9ZhhApEw?view_as=subscriber

Subscribe my personal YouTube Channel:

Let's Start

 Watch My Complete Camera Video:

https://www.youtube.com/watch?v=WL9okRCtwG8

Description:

In this video, I am going to show to how to take image in your application using camera. First I take image using camera and then show in imageview. So Let's Start.

1)  Paste Code to Manifests.

 

2) Paste Code to MainActivity.java.

public class MainActivity extends Activity {
    static final int REQUEST_IMAGE_CAPTURE = 1;
    ImageView imageView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView=findViewById(R.id.imageView);
    }

    public void OpenCamera(View view){
        dispatchTakePictureIntent();
    }
    private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            imageView.setImageURI(fileUri);
        }
    }
}

3) Paste Code to Main Activity.xml.


    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
   





This post first appeared on AR Programming, please read the originial post: here

Share the post

Camera In Android Studio

×

Subscribe to Ar Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×