title: Get File from Uri after Image Capture
body: <p>I need to take a photo with the camera using an activity. In my onActivityResult I am able to retrieve an uri, but I cannot get the file of this uri by using the File constructor. My intent looks like this:</p>
  
  <pre><code>   Intent cameraintent = new Intent("android.media.action.IMAGE_CAPTURE");
     File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
     cameraintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
     imageURICamera = Uri.fromFile(photo);
     startActivityForResult(cameraintent, 1);
  </code></pre>
  
  <p>I use the global defined "imageURICamera" in onActivityResult. I think that the problem has something to do with the Uri not having the proper attributes as the <a href="http://developer.android.com/reference/java/io/File.html#File(java.net.URI)" rel="nofollow">documentation</a> for the file constructor states that:</p>
  
  <p>"Constructs a new File using the path of the specified URI. uri needs to be an absolute and hierarchical Unified Resource Identifier with file scheme and non-empty path component, but with undefined authority, query or fragment components"</p>
  
  <p>My onActivityResult looks like this at the moment:</p>
  
  <pre><code> Uri u = imageURICamera;
   getContentResolver().notifyChange(u, null);
   ContentResolver cr = getContentResolver();
   Bitmap bm;
   try {
      bm = android.provider.MediaStore.Images.Media.getBitmap(cr, u);
      String path = getRealPathFromURI(u);
      File f = new File(path);
  </code></pre>
  
  <p>When i try to query the contentProvider for the path i get the following logcat output:</p>
  
  <pre><code>   07-25 20:04:04.310: ERROR/AndroidRuntime(16438): FATAL EXCEPTION: main
     07-25 20:04:04.310: ERROR/AndroidRuntime(16438): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {tod.dosetracker/tod.dosetracker.ImageViewerActivity}: java.lang.NullPointerException
     07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
     07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
     07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.access$2000(ActivityThread.java:117)
     07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
     07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at  android.os.Handler.dispatchMessage(Handler.java:99)
     07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at       android.os.Looper.loop(Looper.java:123)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.main(ActivityThread.java:3691)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at java.lang.reflect.Method.invokeNative(Native Method)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at java.lang.reflect.Method.invoke(Method.java:507)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at dalvik.system.NativeStart.main(Native Method)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438): Caused by: java.lang.NullPointerException
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at tod.dosetracker.ImageViewerActivity.getRealPathFromURI(ImageViewerActivity.java:315)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at tod.dosetracker.ImageViewerActivity.onActivityResult(ImageViewerActivity.java:251)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at  android.app.Activity.dispatchActivityResult(Activity.java:3934)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
    07-25 20:04:04.310: ERROR/AndroidRuntime(16438):     ... 11 more
    07-25 20:04:04.315: ERROR/(2696): Dumpstate &gt; /data/log/dumpstate_app_error
  </code></pre>