Question

I am able to use my camera and take pictures by below:

public class ImportCard extends Activity {

ImageButton importimage;
Button btnglry, btnqr;
boolean taken;
String path;

protected static final String PHOTO_TAKEN   = "photo_taken";
static Uri capturedImageUri=null;

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

setContentView(R.layout.activity_import_card);

path = Environment.getExternalStorageDirectory() + "/MapCards/"+System.currentTimeMillis()+".jpg";



String dir = Environment.getExternalStorageDirectory().getPath();

File imageDirectory = new File(dir);

imageDirectory.mkdirs();


importimage = (ImageButton)findViewById(R.id.importimage);

importimage.setOnClickListener(new OnClickListener(){   
public void onClick(View v) { 

startCameraActivity();
        }
    }); 

}

protected void 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);

}


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

    taken = true;

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

This method works. But i want my captured images to save in a default target folder such as "MapCards" (if no folder, then create). It is something to do with,

path = Environment.getExternalStorageDirectory() + "/MapCards/"+System.currentTimeMillis()+".jpg";

But all images are saved in "Camera" folder. Thank you for your helps.

Was it helpful?

Solution

Create your own folder in SD card & then pass the File Uri as extra with camera intent. This code should do the trick.

String SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator + "tempImage.jpg";
File file =new File(SD_CARD_TEMP_DIR);    
takePictureFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));

OTHER TIPS

Refer to Android's training-Taking Photos Simply.

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

is the only way to save image to custom file path. so what you should do: 1. check whether you have the correct saving folder 2. try to remove your sdcard to verify whether your code can work 3. Is your ROM customized? the 3rd-party ROM may not work well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top