[android-developers] Re: fwd: get the file path from a URI instance
On Nov 17, 7:06 am, Streets Of Boston flyingdutc...@gmail.com wrote: When using openInputStream on the content-resolver, the returned input- stream is not as 'flexible' as a FileInputStream. For example, FileInputStreams can be retried if something goes wrong. The one returned by openInputStream can not. What is an example of something going wrong? Are there Exceptions you would catch and ignore while reading a FileInputStream? Togetthe fully qualifiedpath-name to the image-file(jpg/png), query theUriof the image and obtain the value of the DATA (_data) column. This value is a String, the fully-qualifiedpathto the imagefile. Then you can create a FileInputStream from thisfile. On Nov 17, 4:08 am, MrChaz mrchazmob...@googlemail.com wrote: If I remember rightly, the gallery returns you a contenturi so you'll want to do something like: getContentResolver ().openInputStream(uri) On Nov 17, 5:53 am, Abhi abhishek.r.sha...@gmail.com wrote: Hi Dianne, I am trying to do the following. I have an Image viewer where in the user picks an Image from within the gallery. Theurito that selected Image is available to me. Now, I want to use thisURIinformation and send it as afileover a socket using FileInputStream. Is this a valid syntax to perform the above action? FileInputStream fis = new FileInputStream(uri.getPath()); // Hereuriis theURIof the selected Image byte[] buffer = new byte[fis.available()]; fis.read(buffer); ObjectOutputStream oos = new ObjectOutputStream (socket.getOutputStream()); oos.writeObject(buffer); Please help me to move forward. Thanks, Abhi- Hide quoted text - - Show quoted text - -- 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
[android-developers] Re: fwd: get the file path from a URI instance
Thanks! I never thought about going through the file-descriptor. But why is using the DATA column discouraged? It works fine and it's a public column (not part of a private API or such). On Nov 17, 12:42 pm, Dianne Hackborn hack...@android.com wrote: On Tue, Nov 17, 2009 at 7:06 AM, Streets Of Boston flyingdutc...@gmail.comwrote: To get the fully qualified path-name to the image-file (jpg/png), query the Uri of the image and obtain the value of the DATA (_data) column. This value is a String, the fully-qualified path to the image file. Then you can create a FileInputStream from this file. No, don't do this. Use ContentResolver.openFile() and create a FileInputStream or whatever from the FileDescriptor: http://developer.android.com/reference/android/content/ContentProvide..., java.lang.String) -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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
Re: [android-developers] Re: fwd: get the file path from a URI instance
That only works if the provider's data exists somewhere that is world-readable, which is basically only the media provider. It really shouldn't be specified as a generic column, but something very specific to the media provider. I would strongly recommend not using it. On Wed, Nov 25, 2009 at 11:29 AM, Streets Of Boston flyingdutc...@gmail.com wrote: Thanks! I never thought about going through the file-descriptor. But why is using the DATA column discouraged? It works fine and it's a public column (not part of a private API or such). On Nov 17, 12:42 pm, Dianne Hackborn hack...@android.com wrote: On Tue, Nov 17, 2009 at 7:06 AM, Streets Of Boston flyingdutc...@gmail.comwrote: To get the fully qualified path-name to the image-file (jpg/png), query the Uri of the image and obtain the value of the DATA (_data) column. This value is a String, the fully-qualified path to the image file. Then you can create a FileInputStream from this file. No, don't do this. Use ContentResolver.openFile() and create a FileInputStream or whatever from the FileDescriptor: http://developer.android.com/reference/android/content/ContentProvide.. ., java.lang.String) -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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
[android-developers] Re: fwd: get the file path from a URI instance
But if you know when you're dealing with images from the media- provider that are stored on the SD-card, then using the MediaStore.Images.ImageColumns.DATA column should be fine? On Nov 25, 3:34 pm, Dianne Hackborn hack...@android.com wrote: That only works if the provider's data exists somewhere that is world-readable, which is basically only the media provider. It really shouldn't be specified as a generic column, but something very specific to the media provider. I would strongly recommend not using it. On Wed, Nov 25, 2009 at 11:29 AM, Streets Of Boston flyingdutc...@gmail.com wrote: Thanks! I never thought about going through the file-descriptor. But why is using the DATA column discouraged? It works fine and it's a public column (not part of a private API or such). On Nov 17, 12:42 pm, Dianne Hackborn hack...@android.com wrote: On Tue, Nov 17, 2009 at 7:06 AM, Streets Of Boston flyingdutc...@gmail.comwrote: To get the fully qualified path-name to the image-file (jpg/png), query the Uri of the image and obtain the value of the DATA (_data) column. This value is a String, the fully-qualified path to the image file. Then you can create a FileInputStream from this file. No, don't do this. Use ContentResolver.openFile() and create a FileInputStream or whatever from the FileDescriptor: http://developer.android.com/reference/android/content/ContentProvide.. ., java.lang.String) -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them.- Hide quoted text - - Show quoted text - -- 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
Re: [android-developers] Re: fwd: get the file path from a URI instance
If you know exactly that is what you are dealing with, okay. On Wed, Nov 25, 2009 at 6:46 PM, Streets Of Boston flyingdutc...@gmail.comwrote: But if you know when you're dealing with images from the media- provider that are stored on the SD-card, then using the MediaStore.Images.ImageColumns.DATA column should be fine? On Nov 25, 3:34 pm, Dianne Hackborn hack...@android.com wrote: That only works if the provider's data exists somewhere that is world-readable, which is basically only the media provider. It really shouldn't be specified as a generic column, but something very specific to the media provider. I would strongly recommend not using it. On Wed, Nov 25, 2009 at 11:29 AM, Streets Of Boston flyingdutc...@gmail.com wrote: Thanks! I never thought about going through the file-descriptor. But why is using the DATA column discouraged? It works fine and it's a public column (not part of a private API or such). On Nov 17, 12:42 pm, Dianne Hackborn hack...@android.com wrote: On Tue, Nov 17, 2009 at 7:06 AM, Streets Of Boston flyingdutc...@gmail.comwrote: To get the fully qualified path-name to the image-file (jpg/png), query the Uri of the image and obtain the value of the DATA (_data) column. This value is a String, the fully-qualified path to the image file. Then you can create a FileInputStream from this file. No, don't do this. Use ContentResolver.openFile() and create a FileInputStream or whatever from the FileDescriptor: http://developer.android.com/reference/android/content/ContentProvide .. ., java.lang.String) -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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.comandroid-developers%2bunsubscr...@googlegroups.com android-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them.- Hide quoted text - - Show quoted text - -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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
[android-developers] Re: fwd: get the file path from a URI instance
If I remember rightly, the gallery returns you a content uri so you'll want to do something like: getContentResolver ().openInputStream(uri) On Nov 17, 5:53 am, Abhi abhishek.r.sha...@gmail.com wrote: Hi Dianne, I am trying to do the following. I have an Image viewer where in the user picks an Image from within the gallery. The uri to that selected Image is available to me. Now, I want to use this URI information and send it as a file over a socket using FileInputStream. Is this a valid syntax to perform the above action? FileInputStream fis = new FileInputStream(uri.getPath()); // Here uri is the URI of the selected Image byte[] buffer = new byte[fis.available()]; fis.read(buffer); ObjectOutputStream oos = new ObjectOutputStream (socket.getOutputStream()); oos.writeObject(buffer); Please help me to move forward. Thanks, Abhi -- 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
[android-developers] Re: fwd: get the file path from a URI instance
When using openInputStream on the content-resolver, the returned input- stream is not as 'flexible' as a FileInputStream. For example, FileInputStreams can be retried if something goes wrong. The one returned by openInputStream can not. To get the fully qualified path-name to the image-file (jpg/png), query the Uri of the image and obtain the value of the DATA (_data) column. This value is a String, the fully-qualified path to the image file. Then you can create a FileInputStream from this file. On Nov 17, 4:08 am, MrChaz mrchazmob...@googlemail.com wrote: If I remember rightly, the gallery returns you a content uri so you'll want to do something like: getContentResolver ().openInputStream(uri) On Nov 17, 5:53 am, Abhi abhishek.r.sha...@gmail.com wrote: Hi Dianne, I am trying to do the following. I have an Image viewer where in the user picks an Image from within the gallery. The uri to that selected Image is available to me. Now, I want to use this URI information and send it as a file over a socket using FileInputStream. Is this a valid syntax to perform the above action? FileInputStream fis = new FileInputStream(uri.getPath()); // Here uri is the URI of the selected Image byte[] buffer = new byte[fis.available()]; fis.read(buffer); ObjectOutputStream oos = new ObjectOutputStream (socket.getOutputStream()); oos.writeObject(buffer); Please help me to move forward. Thanks, Abhi- Hide quoted text - - Show quoted text - -- 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
[android-developers] Re: fwd: get the file path from a URI instance
Thank you so much guys. I have it working as below... Cursor cursor = getContentResolver().query(uri, null, null, null, null); cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); String absoluteFilePath = cursor.getString(idx); FileInputStream fis = new FileInputStream(absoluteFilePath); ... and so on Regards, Abhi On Nov 17, 10:06 am, Streets Of Boston flyingdutc...@gmail.com wrote: When using openInputStream on the content-resolver, the returned input- stream is not as 'flexible' as a FileInputStream. For example, FileInputStreams can be retried if something goes wrong. The one returned by openInputStream can not. To get the fully qualified path-name to the image-file (jpg/png), query the Uri of the image and obtain the value of the DATA (_data) column. This value is a String, the fully-qualified path to the image file. Then you can create a FileInputStream from this file. On Nov 17, 4:08 am, MrChaz mrchazmob...@googlemail.com wrote: If I remember rightly, the gallery returns you a content uri so you'll want to do something like: getContentResolver ().openInputStream(uri) On Nov 17, 5:53 am, Abhi abhishek.r.sha...@gmail.com wrote: Hi Dianne, I am trying to do the following. I have an Image viewer where in the user picks an Image from within the gallery. The uri to that selected Image is available to me. Now, I want to use this URI information and send it as a file over a socket using FileInputStream. Is this a valid syntax to perform the above action? FileInputStream fis = new FileInputStream(uri.getPath()); // Here uri is the URI of the selected Image byte[] buffer = new byte[fis.available()]; fis.read(buffer); ObjectOutputStream oos = new ObjectOutputStream (socket.getOutputStream()); oos.writeObject(buffer); Please help me to move forward. Thanks, Abhi- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text - -- 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
Re: [android-developers] Re: fwd: get the file path from a URI instance
On Tue, Nov 17, 2009 at 7:06 AM, Streets Of Boston flyingdutc...@gmail.comwrote: To get the fully qualified path-name to the image-file (jpg/png), query the Uri of the image and obtain the value of the DATA (_data) column. This value is a String, the fully-qualified path to the image file. Then you can create a FileInputStream from this file. No, don't do this. Use ContentResolver.openFile() and create a FileInputStream or whatever from the FileDescriptor: http://developer.android.com/reference/android/content/ContentProvider.html#openFile(android.net.Uri, java.lang.String) -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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