Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8836123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:25:09+00:00 2026-06-14T09:25:09+00:00

I am trying to load the camera to take a photo from my android

  • 0

I am trying to load the camera to take a photo from my android app,

my Photos.java is

private Uri imageUri;

public void takePhoto(View view) {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    File photo = new File(Environment.getExternalStorageDirectory(),  "Pic.jpg");
    intent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);
    startActivityForResult(intent, TAKE_PICTURE);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case TAKE_PICTURE:
        if (resultCode == Activity.RESULT_OK) {
            Uri selectedImage = imageUri;
            getContentResolver().notifyChange(selectedImage, null);
            ImageView imageView = (ImageView) findViewById(R.id.ImageView);
            ContentResolver cr = getContentResolver();
            Bitmap bitmap;
            try {
                 bitmap = android.provider.MediaStore.Images.Media
                 .getBitmap(cr, selectedImage);

                imageView.setImageBitmap(bitmap);
                Toast.makeText(this, selectedImage.toString(),
                        Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT)
                        .show();
                Log.e("Camera", e.toString());
            }
        }
    }

and this works great. But its the layout section to call this intent which I am struggling with.

I created a button to load the camera

<Button
    android:id="@+id/takePhoto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="41dp"
    android:onClick="takePhoto"
    android:text="@string/Photos_Button1" />

but now I need to have a section to show the image I have taken. How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:25:10+00:00Added an answer on June 14, 2026 at 9:25 am

    Give this a try…

    NOTE : Only applicable to Android API 8 // 2.2 or higher

    public class PhotoActivity extends Activity {
    
        /** The Constant PICK_IMAGE. */
        private static final int PICK_IMAGE = 0;
    
        /** The Constant PICK_IMAGE_FROM_GALLERY. */
        private static final int PICK_IMAGE_FROM_GALLERY = 1;
    
        /** The btn cancel. */
        private Button btnPhotoCamera,btnPhotoGallery,btnCancel;
    
        /** The img view. */
        private ImageView imgView;
    
        /** The u. */
        private Uri u;
    
        /* (non-Javadoc)
         * @see android.app.Activity#onCreate(android.os.Bundle)
         */
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_photo_options);
    
            imgView=(ImageView)findViewById(R.id.imgDisplayImage);
            btnPhotoCamera=(Button)findViewById(R.id.btnPhotoCamera);
            btnPhotoGallery=(Button)findViewById(R.id.btnPhotoGallery);
            btnCancel=(Button)findViewById(R.id.btnCancel);
    
            btnPhotoCamera.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
    
                    Intent camera=new Intent();
                    camera.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                    camera.putExtra("crop", "true");
    
                    File f=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    
                    u = Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"myFile.jpg"));
                    camera.putExtra(MediaStore.EXTRA_OUTPUT, u);
                    startActivityForResult(camera, PICK_IMAGE);
                }
            });
    
            btnPhotoGallery.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
    
                    Intent intent = new Intent(Intent.ACTION_PICK);
                    intent.setType("image/*");
                    startActivityForResult(intent, PICK_IMAGE_FROM_GALLERY);
                }
            });
    
            btnCancel.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
    
                    Intent goStartUp=new Intent(PhotoActivity.this, StartUpActivity.class);
                    goStartUp.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(goStartUp);
                    finish();
                }
            });
        }
    
        /* (non-Javadoc)
         * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
         */
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            if (resultCode==RESULT_OK )
            {
                if(requestCode == PICK_IMAGE) {
    
                    InputStream is=null;
                    try {
                        is = this.getContentResolver().openInputStream(u);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    Bitmap bmp=BitmapFactory.decodeStream(is);
                    imgView.setImageBitmap(bmp);
                    Log.i("Inside", "PICK_IMAGE");
                }
    
                if (requestCode == PICK_IMAGE_FROM_GALLERY) {
                    Uri selectedImage = data.getData();
                    String[] filePathColumn = { MediaStore.Images.Media.DATA };
                    Log.d("data",filePathColumn[0]);
                    Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
                    cursor.moveToFirst();
                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    String picturePath = cursor.getString(columnIndex);
                    cursor.close();
                    imgView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
                    Log.i("Inside", "PICK_IMAGE_FROM_GALLERY");
                }
            }
        }
    }
    

    XML File:-

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#f0f0f0">
        <TextView
            android:id="@+id/lblSelectOptions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:text="@string/two_options"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#ff0000"/>
        <Button
            android:id="@+id/btnPhotoCamera"
            android:layout_width="75dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lblSelectOptions"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:text="@string/camera"/>
        <Button
            android:id="@+id/btnPhotoGallery"
            android:layout_width="75dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btnPhotoCamera"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:text="@string/gallery"/>
        <Button
            android:id="@+id/btnCancel"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btnPhotoGallery"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="19dp"
            android:text="@string/cancel"/>
        <TextView
            android:id="@+id/lblDisplayImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btnCancel"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:text="@string/below_this_text_image_will_be_displayed"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000"
            android:textSize="13dp"/>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/lblDisplayImage"
            android:layout_centerInParent="true"
            android:layout_marginTop="10dp"
            android:gravity="bottom">
            <!--
                 <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            -->
            <ImageView
                android:id="@+id/imgDisplayImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/lblDisplayImage"
                android:layout_centerInParent="true"
                android:contentDescription="@string/area_where_image_is_to_be_displayed" />
            <!-- </ScrollView> -->
        </RelativeLayout>
    </RelativeLayout>
    

    ALso Modify the Android Manifest file as per your use with following:-

    <manifest....
      <uses-sdk
            android:minSdkVersion="3"
            android:targetSdkVersion="21" />
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-permission android:name="android.permission.RECORD_VIDEO" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-feature
            android:name="android.hardware.camera"
            android:required="false" />
    <application....
    ..........
    </application>
    </manifest>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to mimic the Camera app transition from the front to back camera..
I'm trying to load image (not URL) from either camera or gallery and save
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine
trying to load in a bunch of images into a list from a directory...my
When trying to load Microsoft.Xna.Framework.dll from any project, it throws a FileNotFoundException. The specified
I'm trying to make a basic application that displays an image from the camera,
I'm trying to display a UIImage in real-time coming from the camera, and it
i am trying load file after it created from /stext command line but its
I am trying to scale the photos taken with a camera, but i am
I am trying to invoke camera from HTML5 and JavaScript. My code is as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.