Thank you very much. this is exactly what I want.
thanks again.
On Jul 22, 11:38 pm, Kacper86 <[email protected]> wrote:
> Hi,
>
> Firstly, I'd like to recommend this article:
> http://developer.android.com/guide/topics/providers/content-providers...
>
> Secondly, let's solve your problem (which you can solve on your own
> after reading the article). The Uri is not supposed to carry a large
> amount of data. You don't cast it to huge objects and directly query
> it for the information. Think of it as an address. When you have an
> address and a mean of transport you can get there and find whatever
> you're looking for. To the point, if you have an Uri, you can use
> Cursor and make a proper query, which can look like this:
>
> <android code>
> Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
> Uri u2 = Uri.withAppendedPath(u, "1");
>
> // this is what you have
> // u2 == content://media/external/images/media/1
>
> String[] projection = { MediaStore.Images.ImageColumns.DATA, /
> *col1*/
> MediaStore.Images.ImageColumns.DISPLAY_NAME
> /*col2*/};
>
> Cursor c = managedQuery(u2, projection, null, null, null);
> if (c!=null && c.moveToFirst()) {
> String column0Value = c.getString(0);
> String column1Value = c.getString(1);
> Log.d("Data",column0Value);
> Log.d("Display name",column1Value);
> }
> </android code>
>
> Obviously, you can reduce number of columns to the one you need the
> most. The less number of columns we have to return, the more efficient
> it will get.
>
> On Jul 22, 8:41 pm, Mina Shokry <[email protected]> wrote:
>
> > thank you for this great help but unfortunately this isn't my case.
> > not me who created the cursor and iterate through it. I am just
> > receiving the Uri from another activity via an intent. and it isn't
> > good to iterate through all images to find one its Uri matches one I
> > received especially that I am not sure it will always be a Uri of an
> > image.
>
> > still can I get the file name?
>
> > On Jul 22, 4:04 pm, Kacper86 <[email protected]> wrote:
>
> > > Hi,
>
> > > The problem is that it should be documented in the Android Reference,
> > > here:
>
> > >http://developer.android.com/reference/android/provider/MediaStore.Im......
>
> > > But, as far as i understand, it's not complete. Fortunately, we can
> > > check it in a different way.
>
> > > <android code>
> > > Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
> > > //sdcard only
> > > Cursor c = managedQuery(u, null, null, null, null);
>
> > > if (c.moveToFirst()) {
> > > do {
> > > int max = c.getColumnCount();
> > > for (int i = 0; i < max; i++) {
> > > String colName =
> > > c.getColumnName(i);
> > > String value = c
> > >
> > > .getString(c.getColumnIndex(colName));
>
> > > if (colName != null){
> > > Log.d("columnName: ",
> > > colName);
> > > }
>
> > > if (value != null) {
> > > Log.d("value", value);
> > > }
> > > }
> > > } while (c.moveToNext());
> > > }
> > > </android code>
>
> > > Check LogCat and you'll notice that we have all column names with
> > > their values. I suppose, you'd be interested in:
>
> > > 07-22 12:50:09.973: DEBUG/columnName:(3049): _data
> > > 07-22 12:50:09.973: DEBUG/value(3049): /sdcard/download/vienna-s-
> > > schonbrunn-zoo-and-giant-ferris-wheel-in-vienna-1.jpg
> > > (...)
> > > 07-22 12:50:09.983: DEBUG/columnName:(3049): _display_name
> > > 07-22 12:50:09.983: DEBUG/value(3049): vienna-s-schonbrunn-zoo-and-
> > > giant-ferris-wheel-in-vienna-1.jpg
>
> > > If you have got any questions, don't hesitate to ask.
>
> > > Greetings!
>
> > > On Jul 22, 10:28 am, Mina Shokry <[email protected]> wrote:
>
> > > > Hello,
>
> > > > I am using content provider to access images in phone gallery and
> > > > everything works fine except one thing that I want to get the physical
> > > > file name of images I access. Can I get a java.io.File object from
> > > > android.net.Uri object?
> > > > if no, is there any other way to accomplish such a task?
> > > > I just need to know the file name!
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---