title: ImageView setImageBitmap not working on certain devices
body: <p>I was practicing around with the <code>Camera API</code> for which I did the following:</p>
  
  <p>a. Setup a <strong>directory</strong> for the image captured (for <code>startActivityForResult</code>)</p>
  
  <p>b. Setup the Bitmap so that the image could be shown once saved in the app itself.</p>
  
  <p>Here's the code for the following:</p>
  
  <p>Setting up the directory.</p>
  
  <pre><code>private static File getOutputMediaFile(int type) {
  
      // External sdcard location
      File mediaStorageDir = new File(
              Environment
                      .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
              IMAGE_DIRECTORY_NAME);
      // Create the storage directory if it does not exist
      if (!mediaStorageDir.exists()) {
          if (!mediaStorageDir.mkdirs()) {
              Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
                      + IMAGE_DIRECTORY_NAME + " directory");
              return null;
          }
      }
      // Create a media file name
      String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
              Locale.getDefault()).format(new Date());
      File mediaFile;
      if (type == MEDIA_TYPE_IMAGE) {
          mediaFile = new File(mediaStorageDir.getPath() + File.separator
                  + "IMG_" + timeStamp + ".jpg");
      } else {
          return null;
      }
  
      return mediaFile;
  }
  </code></pre>
  
  <p><strong>Global variables in the application</strong></p>
  
  <pre><code>// Activity request codes
  private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100;
  public static final int MEDIA_TYPE_IMAGE = 1;
  
  // directory name to store the captured images
  private static final String IMAGE_DIRECTORY_NAME = "my_camera_app";
  
  private Uri fileUri;
  
  // Views
  ImageView photo;
  Button camera;
  </code></pre>
  
  <p><strong>Camera implementation logic</strong></p>
  
  <pre><code>// Use camera function
  private void captureImage() {
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
      fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
  
      intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
  
      // start the image capture Intent
      startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      // TODO Auto-generated method stub
      if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
          if (resultCode == RESULT_OK) {
              // Successfully captured the image
              // display in imageview
              previewImage();
          } else {
              // failed to capture image
              Toast.makeText(getApplicationContext(),
                      "Sorry! Failed to capture image", Toast.LENGTH_SHORT)
                      .show();
          }
      }
  }
  
  private void previewImage() {
      try {
          // Bitmap factory
          BitmapFactory.Options options = new BitmapFactory.Options();
  
          // Downsizing image as it throws OutOfMemory exception for larger
          // images
          options.inSampleSize = 3;
  
          final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),
                  options);
  
          photo.setImageBitmap(bitmap);
  
      } catch (NullPointerException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>The problem I am having is that ... for some of the devices that I tested the app, the app shows a blank preview of the image shot while in others the app works completely well.</p>
  
  <p>Why am I getting a blank feedback ? and in some of the cases, when an image is saved, the user is not directed to my app, instead the user is stuck in the camera app.</p>
  
  <p>Please do help.</p>