title: open an camera app by intent and save picture on the SD and imageView
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3597867/using-camera-and-storing-captured-result-in-sdcard-in-android">Using Camera and storing captured result in SDCard in android</a>  </p>
  </blockquote>
  
  
  
  <p>I want to get picture from camera app, save it on SD and set imageView.
  I made a code below. saving and imageView sometimes works. but sometimes the picture is saved on SD and imageView doesn't work.</p>
  
  <p>When imageView doesn't work, it seems that mOutUri become null in onActivityResult. </p>
  
  <p>I have tried to save a mOutUri on SharedPreferences in clkbutton. I can see the uri in onActivityResult but imageView doesn't work. at this time, mOutUri is also null.</p>
  
  <pre><code>public void clkbutton(View v){
      Intent intent = new Intent();
  
      // open camera app
      intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
  
      // save data in SD card
      Date date = new Date();
      DateFormat df = new SimpleDateFormat("yyyy-MM-dd-kk-mm-ss");
      String newPicFile = df.format(date) + ".jpg";
      mNewPicFile = newPicFile;
      String outPath = "/sdcard/" + newPicFile;
      File outFile = new File(outPath);
      mOutUri = Uri.fromFile(outFile);
  
      intent.putExtra(MediaStore.EXTRA_OUTPUT, mOutUri);       
      startActivityForResult(intent, REQUEST_CAPTURE_IMAGE);
  }
  
  
   @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      ImageView imageView = (ImageView) findViewById(R.id.image_view);
      imageView.setImageURI(mOutUri);    
   }
  </code></pre>
  
  <p>It's so weird that it sometimes errors and sometimes works.</p>