This Uri is the logical (not physical) path used by the image content
provider.
If you want to get the physical path to the actual file on the SD-
card, query this Uri:

  Cursor cursor = query(photoUri, new String[]
{MediaStore.Images.ImageColumns.DATA}, null, null, null);
  String absoluteFilePath = cursor.getString(0);

Now, absoluteFilePath is the physical path to your image, which you
can use in Drawable.createFromPath

Question: Why don't you create a Bitmap instead?

   ...
   InputStream is = getContentResolver().openInputStream(photoUri);
   Bitmap bm = BitmapFactory.decodeStream(is);
   ...
   is.close();

I ask this, because it is safer to cache Bitmaps instead of Drawables.
If you cache Drawables, you run the risk of memory leaks. Drawables
have handles to your activity and when your activity gets destroyed
while your Drawables are still cached, your activiy will never be
garbage collected --> memory leak.
Bitmaps don't have this problem. They are basically byte-arrays with
some behavior :).

On Mar 25, 3:15 am, beachy <beachy.g...@gmail.com> wrote:
> In some code I call this;
>                                         Intent photoPickerIntent = new Intent
> (Intent.ACTION_PICK);
>                                     photoPickerIntent.setType("image/*");
>                                     startActivityForResult(photoPickerIntent,
> 1);
>
> then implement this method....
>
> protected void onActivityResult(int requestCode, int resultCode,
> Intent intent)
>         {
>              super.onActivityResult(requestCode, resultCode, intent);
>
>              if (resultCode == RESULT_OK)
>              {
>                      Uri photoUri = intent.getData();
>                      Log.d(TAG, "should be adding a photo");
>                      if (photoUri != null)
>                      {
>
>                              Log.d(TAG, "photo uri is not blank");
>                                  // do something with the content Uri
>                              //TODO figure out why this does not work!!
>                              Log.d(TAG, "the photo URI is " + 
> photoUri.getPath());
>                          Drawable thePic = Drawable.createFromPath
> (photoUri.getPath());
>                          //thePic is Null
>                                      if(thePic != null){
>                              Log.d(TAG, "the pic has loaded");
>                                  myRecipe.addPic(thePic);
>                                  ((RecipeAdapter)myListView.getAdapter
> ()).notifyDataSetChanged();
>
>                          }
>                      }
>              }
>         }
>
> trying to get a image and load it in to a drawable object. The Uri
> that is returned seems logical
>
> 03-25 08:12:58.554: DEBUG/ConvertScaleScreen(174): the photo URI is /
> external/images/media/1
>
> but when i start up a shell with adb the file location or even the
> root drive does not exitst, am I missing something here? should the be
> a symbolic link on the file system?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to