问题
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));
}
回答1:
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().
回答2:
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.
回答3:
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.
回答4:
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.
回答5:
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
来源:https://stackoverflow.com/questions/23928844/what-is-uri-in-android