0

Camera application opens and after capturing image, camera app doesn't close. Also, I have created default directory to save image file but by default it saves into the camera folder.

 private void takePicture(){
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (Util.SystemFeatures.hasCamera(getApplication())) {

        if (imageFile != null) {
            AppLog.showAppFlow("imagefile is not null");
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
            startActivityForResult(intent,CAMERA_ACTIVITY_REQUEST_CODE);
            Toast.makeText(this,"opening camera",Toast.LENGTH_LONG).show();
        } else {
            AppLog.showAppFlow("image file is null");
        }

    }

}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    if(requestCode == CAMERA_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK){
        AppLog.showAppFlow("Image successfully captured");
        Toast.makeText(getApplicationContext(),"Image saved in: "+imageFile.getAbsolutePath(),Toast.LENGTH_LONG).show();
        startNextActivity();
    }
}

private void startNextActivity(){

    Intent i = new Intent(this,confirmImage.class);
    startActivity(i);

}

2 Answers2

-1

For get call onActivityResult you need to start activity witch contents your onActivityResult code for Result

use this

private void startNextActivity(){

    Intent i = new Intent(this,confirmImage.class);
    startActivityForResult(i);

}
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
sourabh devpura
  • 605
  • 8
  • 25
-1

Please try this code. This will create a folder in SD Card as MyCapturedImages and store images in it.

public static final int REQUEST_IMAGE_CAPTURE = 1;
private Bitmap userImageBit;


//on click
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    if (takePictureIntent.resolveActivity(getPackageManager()) != null) 
                    {

                        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
                    }

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {


        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) 
        {
            Bundle extras = data.getExtras();
            userImageBit = (Bitmap) extras.get("data");

//you can use this bitmap userImageBit 

String root = Environment.getExternalStorageDirectory().toString();
        File myDir = new File(root + "/MyCapturedImages");    
        if(myDir.isDirectory())
        {
            myDir.mkdirs();
        }
        myDir.mkdirs();
        Random generator = new Random();
        int n = 10000;
        n = generator.nextInt(n);
        String fname = "MyImage-"+ n +".png";
        File file = new File (myDir, fname);
        if (file.exists ()) file.delete (); 
        try 
        {
            FileOutputStream out = new FileOutputStream(file);
            userImageBit .compress(Bitmap.CompressFormat.PNG, 80, out);
            out.flush();
            out.close();
            System.out.println("on activity of Activity");


            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        }
}
Shoeb Siddique
  • 2,805
  • 1
  • 22
  • 42