-6

I want to create an app that takes photo automatically and store the photo in folder specified, once i press a button. Also tell me how to use intent class to call camera.

1 Answers1

0

Hope this code will help you.

        findViewById(R.id.take_picture).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            takePicture();
        }
    });

 

    private void takePicture() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    try {
        Uri mImageCaptureUri = null;
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            mImageCaptureUri = Uri.fromFile(mFileTemp);
        }
        else {
            /*
             * The solution is taken from here: http://stackoverflow.com/questions/10042695/how-to-get-camera-result-as-a-uri-in-data-folder
             */
            mImageCaptureUri = InternalStorageContentProvider.CONTENT_URI;
        }   
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
        intent.putExtra("return-data", true);
        startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);
    } catch (ActivityNotFoundException e) {

        Log.d(TAG, "cannot take picture", e);
    }
}
Rhn Bhadani
  • 2,208
  • 1
  • 17
  • 25