0

I am trying to take a photo by using an Intent.
My code looks like this and I don't know where the problem is.
When I want to get my app started, I get error:

12-20 06:09:03.243: E/AndroidRuntime(1048): java.lang.RuntimeException: com.android.camera.CameraHardwareException: java.lang.RuntimeException: Fail to connect to camera service
karas
  • 41
  • 1
  • 4

2 Answers2

0

Intent for taking photo is as follows:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);

Now in activity result you will get image capture path.

Hope this helps you

Ghost
  • 3,966
  • 1
  • 25
  • 36
Silvans Solanki
  • 1,267
  • 1
  • 14
  • 27
0

Try this :

      try {


                    File root = new File(Environment.getExternalStorageDirectory()
                            + File.separator + "temp" + File.separator);
                    root.mkdirs();
                    File sdImageMainDirectory = new File(root, "myPicName.jpg");
                     Uri outputFileUri = Uri.fromFile(sdImageMainDirectory);
                    startCameraActivity();
                } catch (Exception e) {

                    Toast.makeText(this, "Error occured. Please try again later.",
                            Toast.LENGTH_SHORT).show();

                }
    protected void startCameraActivity() {



            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(cameraIntent, 101);


        }

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

        if(requestCode==101 && resultCode==-1)
        {
            try
            {
            //   "/mnt/sdcard/temp/myPicName.jpg" is ur image file if u want to use it
            }
            catch(Exception ex)
            {



            }
        }
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109