0

I have a Button, in which I attach a listener to capture a photo. After taking the picture and storing into file, I need to do some post processing. How can I do that?

Here's the code at the button launching

    cameraButton = (ImageButton) rootView.findViewById(R.id.camera_button);
    cameraButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            String fileName = mediaStorageDir.getPath() + File.separator +
                    "IMG_"+ timeStamp + ".jpg";

            Intent intent = new Intent(v.getContext(), CameraCapture.class);
            intent.putExtra("FILE_NAME", fileName);
            startActivityForResult(intent, 100);

            // TODO: do something extra. Right now it does not work
            IWantToDoSomethingExtra();
        }
    });

and the Camera

public class CameraCapture extends Activity {
    private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
    private String fileName;
    private File mediaFile;
    Intent intent;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.clothes_frame);

        intent = getIntent();
        fileName = (String) intent.getExtras().get("FILE_NAME");
        mediaFile = new File(fileName);
        Uri fileUri = Uri.fromFile(mediaFile);

        Intent mediaIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        mediaIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        startActivityForResult(mediaIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                setResult(Activity.RESULT_OK);
                Toast.makeText(this, "New image captured", Toast.LENGTH_LONG).show();
            }
            else if (resultCode == RESULT_CANCELED) {
                Toast.makeText(this, "Photo request canceled", Toast.LENGTH_LONG).show();
            }
            else {
                Toast.makeText(this, "Bugs happened. Please contact us", Toast.LENGTH_LONG).show();
            }
        }
        finish();
    }
}
Linh Nguyen
  • 151
  • 2
  • 6
  • Get the photo file captured by camera and do whatever u whant 2 do with it. – Stan Apr 07 '15 at 19:30
  • I tried (with the fileName above); however, the camera button always executes it before the Camera Intent finishes. – Linh Nguyen Apr 07 '15 at 19:35
  • you should do it from onActivityResult() to be sure camera intent is finished. – Stan Apr 07 '15 at 19:37
  • yes as @Stan stated, you can do what you have done in CameraCapture activity. Write onActivityResult() method for first activity. Check this to learn how to use onActivityResult() : http://stackoverflow.com/a/10407371/3736955 – Jemshit Apr 07 '15 at 19:38

0 Answers0