title: Getting Image from Camera Folder Programatically
body: <p>Folks.</p>
  
  <p>I'm facing a strange issue here. I have an application that you can select an image from Gallery or Camera in a button click. All went well except whenever i select any picture from my camera folder the application just crashed. Hereunder my code </p>
  
  <pre><code>case R.id.camera:
  
          AlertDialog.Builder builder = new AlertDialog.Builder(Splash.this);
  
          builder.setTitle("Choose Image Source");
          builder.setItems(new CharSequence[] { "Gallery", "Camera" },
                  new DialogInterface.OnClickListener() {
  
                      public void onClick(DialogInterface dialog, int which) {
                          switch (which) {
                          case 0:
  
                              Intent intent = new Intent(
                                      Intent.ACTION_GET_CONTENT);
                              intent.setType("image/*");
  
                              Intent chooser = Intent.createChooser(intent,
                                      "Choose a Picture");
                              startActivityForResult(chooser,
                                      ACTION_REQUEST_GALLERY);
  
                              break;
  
                          case 1:
  
                              Intent cameraIntent = new Intent(
                                      android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                              String mImageCaptureUri = null;
                              cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                      mImageCaptureUri);
                              startActivityForResult(cameraIntent,
                                      ACTION_REQUEST_CAMERA);
  
                              break;
  
                          }
                      }
                  });
  
          builder.show();
  
          break;
  </code></pre>
  
  <p>Activity for result :</p>
  
  <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode == RESULT_OK) {
  
          switch (requestCode) {
          case ACTION_REQUEST_GALLERY:
  
  
              Uri selectedImageUri;
  
              selectedImageUri = data == null ? null : data.getData();
  
              cap.setImageURI(selectedImageUri);
  
  
  
              break;
  
          case ACTION_REQUEST_CAMERA:
  
              Bitmap photo = (Bitmap) data.getExtras().get("data");
  
              cap.setImageBitmap(photo);
  
              // CALL THIS METHOD TO GET THE URI FROM THE BITMAP
              Uri tempUri = getImageUri(getApplicationContext(), photo);
  
              // CALL THIS METHOD TO GET THE ACTUAL PATH
              File finalFile = new File(getRealPathFromURI(tempUri));
  
              Toast.makeText(getApplicationContext(),
                      finalFile.getAbsolutePath(), 4000).show();
  
              break;
          }
  
      }
  }
  </code></pre>