1

This question might seem stupid but, I am writing a dissertation about camera API for Android. Right now I'm looking at saving images on a SD Card, but I'm a bit confused about what Uri is and does. Does it parse the image from the camera to the imageView? Is it the path of the image?

I found a tutorial, but it doesn't describe what the Uri is.

The Uri in the code

Uri uri;

final static int MEDIA_TYPE_IMAGE = 1;

uri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

public Uri getOutputMediaFileUri(int type) {
        return Uri.fromFile(getOutputMediaFile(type));
    }
Camo
  • 133
  • 2
  • 14

5 Answers5

3

URI stands for Uniform Resource Identifier. It's basically a path to a file, or a resource on your storage or on the web.

getOutputMediaFileUri(MEDIA_TYPE_IMAGE); thus gets the path to where Images are being stored.

user717572
  • 3,626
  • 7
  • 35
  • 60
  • Thanks for the answer. Is the picture stored temporary then? – Camo May 29 '14 at 08:31
  • Almost but not quite. That's URL (Uniform Resource Locator) definition - a kind of URI that actually allows you to find something. URI can be abstract, just identifying something, but not actually pointing at anything specific; an Example from Wikipedia is `urn:isbn:0-486-27557-4`, which is a valid URI, but not an URL at all. (tl;dr: all URL are URI; not all URI are URL) – Amadan May 29 '14 at 08:35
  • So when I take a picture, I parse it to the imageView by using the URI and with the URI I can get the path and make a file out of it? I am using this tutorial http://www.androidhive.info/2013/09/android-working-with-camera-api/ – Camo May 29 '14 at 08:38
2

In your case Uri does nothing but points to media file which you create in getOutputMediaFile(type) method. I think you are using this http://www.androidhive.info/2013/09/android-working-with-camera-api/ tutorial. As you can see in implementation of getOutputMediaFile(type) it creates new subdirectory and file in Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)

It means that all your images would be stored in this particular storage

To show picture you can use imageView.setImageUri().

olegr
  • 1,999
  • 18
  • 23
0

A Uri is an address that points to something of significance. In the case of ContentProviders, the Uri is usually used to determine which table to use. So event_uri points to the events table and the reminder_uri points to the reminders table. There is really no "default value" for uris.

Soumil Deshpande
  • 1,622
  • 12
  • 14
0

When you start the camera app using startActivityForResult() and when the user has finished clicking the picture, the camera saves the picture in the phone storage. The path to this picture in the phone store is the Uri.

EdmDroid
  • 1,350
  • 1
  • 11
  • 25
  • Thanks for the answer. Is the picture stored temporary then? – Camo May 29 '14 at 08:27
  • No, it is stored permanently in the phone storage. http://developer.android.com/training/camera/photobasics.html will give a more detailed explanation on how to use the Uri – EdmDroid May 29 '14 at 15:53
0

URI stands for Uniform Resource Identifier. It's basically a path to a file, or a resource on your storage or on the web. Uniform Resource Identifier

Madi
  • 1,805
  • 1
  • 15
  • 9