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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:42:59+00:00 2026-05-24T05:42:59+00:00

I’m working on an android application which allows the user to take some photos

  • 0

I’m working on an android application which allows the user to take some photos using the android camera.The user takes this pictures for competing to a photo contest.So, he takes a few photos, which should be saved into a specific destination and after a while he loops between those photos and decide with which one he will compete to the photo contest.
Well, for that the photos should be saved on a specific folder not in the gallery among other photos which are not for the contest.
Currently, I’m just saving the photos to SDcard and I don’t know how should I do to save them in a certain folder.

I must say that I have already built my own camera but still don’t know how to act when comes to saving the images.

And here is how it looks like:

public class EditPhoto extends Activity implements SurfaceHolder.Callback, OnClickListener {
    static final int FOTO_MODE = 0;
    private static final String TAG = "CameraTest";
    Camera mCamera;
    boolean mPreviewRunning = false;
    private Context mContext = this;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        //doing things
   }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }

    Camera.PictureCallback mPictureCallback = new Camera.PictureCallback(){
        public void onPictureTaken(byte[] imageData, Camera c) {

            if (imageData != null) {

                Intent mIntent = new Intent();

                StoreByteImage(mContext, imageData, 50, "ImageName");
                mCamera.startPreview();

                Bundle b = new Bundle();
                b.putByteArray("imageData", imageData);
                Intent i = new Intent(mContext, ImageDisplayActivity.class);
                i.putExtras(b);
                startActivity(i);

                setResult(FOTO_MODE, mIntent);
                finish();

            }
        }
    };



    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    protected void onStop() {
        Log.e(TAG, "onStop");
        super.onStop();
    }

    public void surfaceCreated(SurfaceHolder holder) {
        Log.e(TAG, "surfaceCreated");
        mCamera = Camera.open();

    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Log.e(TAG, "surfaceChanged");
        if (mPreviewRunning) {
            mCamera.stopPreview();
        }

        Camera.Parameters p = mCamera.getParameters();
        List<Size> sizes = p.getSupportedPictureSizes();

        p.setPreviewSize(640, 480);
        p.setPictureSize(213,350);

       mCamera.setParameters(p);
        try {
            mCamera.setPreviewDisplay(holder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mCamera.startPreview();
        mPreviewRunning = true;
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        Log.e(TAG, "surfaceDestroyed");
        mCamera.stopPreview();
        mPreviewRunning = false;
        mCamera.release();
    }

    private SurfaceView mSurfaceView;
    private SurfaceHolder mSurfaceHolder;

     public void onClick(View arg0) {

        mCamera.takePicture(null, mPictureCallback, mPictureCallback);

    }

    public static boolean StoreByteImage(Context mContext, byte[] imageData, int quality, String expName) {

        File sdImageMainDirectory = new File("/sdcard");
        FileOutputStream fileOutputStream = null;
        String nameFile;
        try {

            BitmapFactory.Options options=new BitmapFactory.Options();
            options.inSampleSize = 5;
            Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length,options);
            fileOutputStream = new FileOutputStream(sdImageMainDirectory.toString() +"/image.jpg");
            BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);

            myImage.compress(CompressFormat.JPEG, quality, bos);

            bos.flush();
            bos.close();

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return true;
    }



}

If you could point me in the right direction I would apppreciate it.Thanks

  • 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-05-24T05:43:00+00:00Added an answer on May 24, 2026 at 5:43 am

    Just add the folder name after sdcard (i.e. /sdcard/images/wildlife). To ensure that the specified folder exist, call the method File.mkdirs(). And please don’t use the hard coded string /sdcard to access SDCard, use Environment.getExternalStorageDirectory method. Revert back for any query.

    Edit:

    public class ImageViewActivity extends Activity {
    
        private String[] imageDirs;
        private Spinner dirSpinner;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            getDirs();
    
            populateSpinner();
    
        }
    
        private void populateSpinner() {
            dirSpinner = (Spinner) findViewById(R.id.dirSpinner);
            ArrayAdapter<String> dirAdapter = new ArrayAdapter<String>(
                    getApplicationContext(),
                    android.R.layout.simple_spinner_dropdown_item, imageDirs);
    
            dirAdapter
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            dirSpinner.setAdapter(dirAdapter);
            dirSpinner.setOnItemSelectedListener(new OnImageItemSelectedListener());
        }
    
        /**
         * Retrieves all the image files in the given directory.
         */
        public File[] retrieveContents(String dirPath) {
    
            File parentDir = new File(dirPath);
    
            if (!parentDir.exists()) {
                return null;
            }
    
            if (!parentDir.isDirectory()) {
                return null;
            }
    
            File[] fileContents = null;
    
            FilenameFilter filter = new FilenameFilter();
            fileContents = parentDir.listFiles(filter);
    
            filter = null;
    
            parentDir = null;
    
            return fileContents;
        }
    
        /**
         * Inner class to get images only.
         */
        private class FilenameFilter implements FileFilter {
            @Override
            public boolean accept(File dir) {
                return dir.getName().toLowerCase()
                        .endsWith(".jpg;*.bmp;*.png;*.gif");
            }
        }
    
        /**
         * Returns the names of sub-dirs in Images dir.
         */
        private void getDirs() {
            String parentDir = Environment.getExternalStorageDirectory()
                    + "/Images";
    
            File[] imageFolders = new File(parentDir).listFiles();
            ArrayList<String> dirList = new ArrayList<String>();
    
            for (int i = 0; i < imageFolders.length; i++) {
                if (imageFolders[i].isDirectory()) {
                    dirList.add(imageFolders[i].getName());
                }
            }
    
            imageDirs = (String[]) dirList.toArray(new String[0]);
        }
    
        public class OnImageItemSelectedListener implements OnItemSelectedListener {
    
            public void onItemSelected(AdapterView<?> parent, View view, int position,
                    long id) {
    
                Toast.makeText(
                        parent.getContext(),
                        "The dir is " + parent.getItemAtPosition(position).toString(),
                        Toast.LENGTH_LONG).show();
            }
    
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.