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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:18:31+00:00 2026-06-15T19:18:31+00:00

how to create new folder MyFolder in phone memory and save all captured images

  • 0

how to create new folder “MyFolder” in phone memory and save all captured images on that folder?
Please help me. The following code save all images to Phone’s default Image gallery. I want to create new folder and save all captured images on that folder. what should I do?

    public class PhotoCaptureExample extends Activity 
  {
protected Button _button;
protected ImageView _image;
protected TextView _field;
protected String _path;
protected boolean _taken;

protected static final String PHOTO_TAKEN   = "photo_taken";

 @Override
  public void onCreate(Bundle savedInstanceState) 
 {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    _image = ( ImageView ) findViewById( R.id.image );
    _field = ( TextView ) findViewById( R.id.field );
    _button = ( Button ) findViewById( R.id.button );
    _button.setOnClickListener( new ButtonClickHandler() );
   ;
  _path = Environment.getExternalStorageDirectory() + "/myfolder   
 /"+System.currentTimeMillis()+".jpg";




    File dir = new File(_path );
    try{
      if(dir.mkdir()) {
         System.out.println("Directory created");
      } 
      else {
         System.out.println("Directory is not created");
      }}
      catch(Exception e){

    }  



















}

public class ButtonClickHandler implements View.OnClickListener 
{
    public void onClick( View view ){
        Log.i("MakeMachine", "ButtonClickHandler.onClick()" );
        startCameraActivity();
    }
}

protected void startCameraActivity()
{
    Log.i("MakeMachine", "startCameraActivity()" );
    File file = new File( _path );
    Uri outputFileUri = Uri.fromFile( file );

    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
    intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );

    startActivityForResult( intent, 0 );
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{   
    Log.i( "MakeMachine", "resultCode: " + resultCode );
    switch( resultCode )
    {
        case 0:
            Log.i( "MakeMachine", "User cancelled" );
            break;

        case -1:
            onPhotoTaken();
            break;
    }
}

protected void onPhotoTaken()
{
    Log.i( "MakeMachine", "onPhotoTaken" );

    _taken = true;

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;

    Bitmap bitmap = BitmapFactory.decodeFile( _path, options );

    _image.setImageBitmap(bitmap);

    _field.setVisibility( View.GONE );
}

@Override 
protected void onRestoreInstanceState( Bundle savedInstanceState){
    Log.i( "MakeMachine", "onRestoreInstanceState()");
    if( savedInstanceState.getBoolean( PhotoCaptureExample.PHOTO_TAKEN ) ) {
        onPhotoTaken();
    }
}

@Override
protected void onSaveInstanceState( Bundle outState ) {
    outState.putBoolean( PhotoCaptureExample.PHOTO_TAKEN, _taken );
}
}
  • 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-15T19:18:32+00:00Added an answer on June 15, 2026 at 7:18 pm

    You need Following permissions in your manifest file to create folder.

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />  
    

    UPDATED :

    package com.test;
    
    import java.io.File;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.MediaStore;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    
    public class CameraTest extends Activity 
    {
        protected Button _button;
        protected ImageView _image;
        protected TextView _field;
        protected String _path;
        protected boolean _taken;
    
    protected static final String PHOTO_TAKEN   = "photo_taken";
    
     @Override
      public void onCreate(Bundle savedInstanceState) 
     {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.camtest);
    
        _image = ( ImageView ) findViewById( R.id.image );
        _field = ( TextView ) findViewById( R.id.field );
        _button = ( Button ) findViewById( R.id.button );
        _button.setOnClickListener( new ButtonClickHandler() );
       // _path = Environment.getExternalStorageDirectory() + "/NewFolder/"+System.currentTimeMillis()+".jpg";
    
        _path = "/sdcard/NewFolder/test1.jpg";
    
    
        String dir = "/sdcard/NewFolder/";
        File imageDirectory = new File(dir);
        imageDirectory.mkdirs();
    
       /* File dir = new File(_path );
        try{
          if(dir.mkdir()) {
             System.out.println("Directory created");
          } 
          else {
             System.out.println("Directory is not created");
          }}
          catch(Exception e){
    
        }  */
    }
    
    public class ButtonClickHandler implements View.OnClickListener 
    {
        public void onClick( View view ){
            Log.i("MakeMachine", "ButtonClickHandler.onClick()" );
            startCameraActivity();
        }
    }
    
    protected void startCameraActivity()
    {
        Log.i("MakeMachine", "startCameraActivity()" );
        File file = new File( _path );
        Uri outputFileUri = Uri.fromFile( file );
    
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
        intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
    
        startActivityForResult( intent, 0 );
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {   
        Log.i( "MakeMachine", "resultCode: " + resultCode );
        switch( resultCode )
        {
            case 0:
                Log.i( "MakeMachine", "User cancelled" );
                break;
    
            case -1:
                onPhotoTaken();
                break;
        }
    }
    
    protected void onPhotoTaken()
    {
        Log.i( "MakeMachine", "onPhotoTaken" );
    
        _taken = true;
    
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 4;
    
        Bitmap bitmap = BitmapFactory.decodeFile( _path, options );
    
        _image.setImageBitmap(bitmap);
    
        _field.setVisibility( View.GONE );
    }
    
    
    }
    

    This works perfectly for me.

    Check out with this code.

    Hope this helps you.

    Thanks.

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

Sidebar

Related Questions

I tried to create a new folder following the instructions at https://developers.google.com/google-apps/documents-list/#creating_a_new_document_or_file_with_metadata_only instead of
Is it possible to create a new folder for images (to be taken through
I have a Repeater that takes all my images in a folder and display
I have the following code which creates a shared folder if (!(Test-Path c:\myFolder)) {
I am using Plupload with codeignitor. My problem is i cant create new folder
Why does the application restart automatically when we create a new folder under a
Very often, I just create a new folder and test things out in there.
When I create a new form under a sub-folder in VS2008 in a C++/CLI
If I create new folder in a Visual Studio project, Visual Studio will automatically
I am creating a script to create new folder hierarchies for a friend of

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.