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 8194789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:56:12+00:00 2026-06-07T04:56:12+00:00

I am trying to learn how to use the camera in my android application.

  • 0

I am trying to learn how to use the camera in my android application. I currently have a working preview with overlaying buttons. I have it set up to successfully take a photo, however when I try to save the photo to the SD card, it is not working correctly. It always comes back “error during saving”.

I know that it is not my SD card, and I have used almost the same exact code before in another app to save a bitmap, which works successfully.

I also know that it is successfully taking a photo, because I tested it by having it place the photo into an ImageView in the activity.

I’m not sure why this isn’t working.

Button takePhoto = (Button)findViewById(R.id.takephoto);
    takePhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {



            mCamera.takePicture(shutterCallback, rawCallback,
                    jpegCallback);




        }
    });




}


ShutterCallback shutterCallback = new ShutterCallback() {
    public void onShutter() {

    }
};

/** Handles data for raw picture */
PictureCallback rawCallback = new PictureCallback() {
    public void onPictureTaken(byte[] arg0, Camera camera) {



    }
};

/** Handles data for jpeg picture */
PictureCallback jpegCallback = new PictureCallback() {
    public void onPictureTaken(byte[] arg0, Camera camera) {

        Bitmap photo = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);

        tempSavePhoto(photo);

        switchToPolaroidView();

    }
};



public void tempSavePhoto(Bitmap photo){

    File root = new File(Environment.getExternalStorageDirectory() + File.separator + "Photos");
    File image = new File(root, "toSend.jpg");
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));

    boolean success = false;

    FileOutputStream outStream;
    try {

        outStream = new FileOutputStream(image);
        photo.compress(Bitmap.CompressFormat.PNG, 100, outStream); 
        /* 100 to keep full quality of the image */

        outStream.flush();
        outStream.close();
        success = true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (success) {
        Toast.makeText(getApplicationContext(), "Saved successfully",
                Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(getApplicationContext(),
                "Error during image saving", Toast.LENGTH_SHORT).show();
    }
}
  • 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-07T04:56:13+00:00Added an answer on June 7, 2026 at 4:56 am

    I tried a different approach and it worked. Not sure why the other one wasn’t working, but it is saving the photo just fine now. Here is what I used instead:

    public void tempSavePhoto(Bitmap photo){
    
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        photo.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
    
    
        File f = new File(Environment.getExternalStorageDirectory()
                                + File.separator + "test.jpg");
        try {
            f.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        FileOutputStream fo = null;
        try {
            fo = new FileOutputStream(f);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            fo.write(bytes.toByteArray());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
    
    
    }
    

    Please note I got this idea from this post, and voted up the answer that helped me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to learn to to use Android SDK and have encountered my
I'm trying to learn how to use the force.layout features in D3.js and have
I am trying to learn and use html5 and have a basic layout but
I am trying to learn how to use Cascadding Style Sheets. I have a
I have been trying to learn to use github, it has been fine until
I'm trying to learn to use the Bing Maps API for Android. I downloaded
I'm trying to learn to use ANTLR, and seem to have come across an
I've been trying to learn how to use the ActionbarSherlock to customize my application
I'm trying to learn to use xml in Java (Android platform, using Eclipse and
I'm trying to learn to use vimdiff well. Currently I figured out how to

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.