[android-developers] Re: Photo Picker
Here is the solution: You have to move your cursor from position "-1" to "0" using moveToFirst(): android.database.Cursor cursor = activity.getContentResolver().query( intent.getData(), null, null, null, null); cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); String fname = cursor.getString(idx); Peli www.openintents.org On 1 Apr., 16:03, Bobbie wrote: > Here's my debug errors: > > 04-01 10:01:33.318: ERROR/AndroidRuntime(30289): Uncaught handler: > thread main exiting due to uncaught exception > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): > java.lang.RuntimeException: Failure delivering result ResultInfo > {who=null, request=1, result=-1, data=Intent { data=content://media/ > external/images/media/2 }} to activity {com.app.name/ > com.app.name.activity}: > android.database.CursorIndexOutOfBoundsException: Index -1 requested, > with a size of 1 > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.app.ActivityThread.deliverResults(ActivityThread.java:2840) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.app.ActivityThread.handleSendResult(ActivityThread.java:2882) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.app.ActivityThread.access$2300(ActivityThread.java:112) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1609) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.os.Handler.dispatchMessage(Handler.java:88) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.os.Looper.loop(Looper.java:123) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.app.ActivityThread.main(ActivityThread.java:3739) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > java.lang.reflect.Method.invokeNative(Native Method) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > java.lang.reflect.Method.invoke(Method.java:515) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run > (ZygoteInit.java:739) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > dalvik.system.NativeStart.main(Native Method) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): Caused by: > android.database.CursorIndexOutOfBoundsException: Index -1 requested, > with a size of 1 > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.database.AbstractCursor.checkPosition(AbstractCursor.java:559) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.database.AbstractWindowedCursor.checkPosition > (AbstractWindowedCursor.java:172) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.database.AbstractWindowedCursor.getString > (AbstractWindowedCursor.java:41) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.database.CursorWrapper.getString(CursorWrapper.java:138) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > com.indigital.IM911.IM911.onActivityResult(IM911.java:516) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.app.Activity.dispatchActivityResult(Activity.java:3415) > 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at > android.app.ActivityThread.deliverResults(ActivityThread.java:2836) > > On Apr 1, 9:52 am, Bobbie wrote: > > > Any other ideas Boston? Eclipse won't even let me compile that code > > without putting it in debug mode, so there is something different in > > that code. Could you take another look? Thanks! > > > On Mar 31, 5:57 pm, Bobbie wrote: > > > > No, I have nothing in onPause(). I guess I'll just have to keep > > > playing with it. > > > > Bobbie > > > > On Mar 31, 4:05 pm, Streets Of Boston wrote: > > > > > Do you have code in your 'onPause()' method of your activity. > > > > If so, it looks like this code is blocking (never returning). > > > > > On Mar 31, 11:39 am, Bobbie wrote: > > > > > > When I choose theimage, this is what Igetin the debug log: > > > > > > 03-31 11:34:36.055: INFO/ActivityManager(55): Displayed activity > > > > > com.android.camera/.ImageGallery2: 2455 ms > > > > > 03-31 11:34:39.525: VERBOSE/ImageGallery2(11143): / > > > > > ImageBlockManager.onPause > > > > > 03-31 11:34:49.519: WARN/ActivityManager(55): Launch timeout has > > > > > expired, giving up wake lock! > > > > > > On Mar 31, 10:24 am, Streets Of Boston > > > > > wrote: > > > > > > > Did you debug it? > > > > > > Did yougeta null-pointer-exception? > > > > > > > (The code i gave you may have some issues: I just typed it in, > > > > > > without > > > > > > using any IDE such as Eclipse. But it should give you a general idea > > > > > > of what to do) > > > > > > > On Mar 30, 10:16 pm, Bobbie wrote: > > > > > > > > I must have a bad phone or something... Now the program force > > > > > > > closes > > > > > >
[android-developers] Re: photo picker Uri issue
You have to call moveToNext or moveToPosition first before you can use the cursor. On Apr 1, 2:13 pm, Bobbie wrote: > The exception is: > > 04-01 14:09:30.274: ERROR/AndroidRuntime(719): > java.lang.RuntimeException: Failure delivering result ResultInfo > {who=null, request=1, result=-1, data=Intent { data=content://media/ > external/images/media/7 }} to activity {com.app.name/ > com.app.name.activity}: > android.database.CursorIndexOutOfBoundsException: Index -1 requested, > with a size of 1 > > What does that mean? > > On Apr 1, 9:44 am, Streets Of Boston wrote: > > > > > I can't tell. > > > Debug your code and see which statement throws an exception and see > > what exception is thrown and note the values of the variables (are > > some set to null when they shouldn't, for example). > > > On Apr 1, 9:35 am, Bobbie wrote: > > > > I tried this code, and every time it force closes. The Uri object > > > gives me the Uri, but I can't see why it's failing... Please help!!! > > > > Uri photoUri = intent.getData(); > > > Cursor cursor = getContentResolver().query(photoUri, new String[] > > > {MediaStore.Images.ImageColumns.DATA}, null, null, null); > > > String absoluteFilePath = cursor.getString(0); > > > > On Mar 26, 8:57 am, beachy wrote: > > > > > cheers, did not know that about Drawables will use Bitmaps then. > > > > > Thanks, > > > > Greg. > > > > > On Mar 25, 3:23 pm, Streets Of Boston wrote: > > > > > > This Uri is the logical (not physical) path used by theimagecontent > > > > > 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 yourimage, 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 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 aimageand 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
[android-developers] Re: photo picker Uri issue
The exception is: 04-01 14:09:30.274: ERROR/AndroidRuntime(719): java.lang.RuntimeException: Failure delivering result ResultInfo {who=null, request=1, result=-1, data=Intent { data=content://media/ external/images/media/7 }} to activity {com.app.name/ com.app.name.activity}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 What does that mean? On Apr 1, 9:44 am, Streets Of Boston wrote: > I can't tell. > > Debug your code and see which statement throws an exception and see > what exception is thrown and note the values of the variables (are > some set to null when they shouldn't, for example). > > On Apr 1, 9:35 am, Bobbie wrote: > > > I tried this code, and every time it force closes. The Uri object > > gives me the Uri, but I can't see why it's failing... Please help!!! > > > Uri photoUri = intent.getData(); > > Cursor cursor = getContentResolver().query(photoUri, new String[] > > {MediaStore.Images.ImageColumns.DATA}, null, null, null); > > String absoluteFilePath = cursor.getString(0); > > > On Mar 26, 8:57 am, beachy wrote: > > > > cheers, did not know that about Drawables will use Bitmaps then. > > > > Thanks, > > > Greg. > > > > On Mar 25, 3:23 pm, Streets Of Boston wrote: > > > > > This Uri is the logical (not physical) path used by theimagecontent > > > > 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 yourimage, 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 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 aimageand 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?- Hide quoted text - > > > - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android
[android-developers] Re: Photo Picker
Here's my debug errors: 04-01 10:01:33.318: ERROR/AndroidRuntime(30289): Uncaught handler: thread main exiting due to uncaught exception 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): java.lang.RuntimeException: Failure delivering result ResultInfo {who=null, request=1, result=-1, data=Intent { data=content://media/ external/images/media/2 }} to activity {com.app.name/ com.app.name.activity}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.app.ActivityThread.deliverResults(ActivityThread.java:2840) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2882) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.app.ActivityThread.access$2300(ActivityThread.java:112) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1609) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.os.Handler.dispatchMessage(Handler.java:88) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.os.Looper.loop(Looper.java:123) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.app.ActivityThread.main(ActivityThread.java:3739) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at java.lang.reflect.Method.invokeNative(Native Method) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at java.lang.reflect.Method.invoke(Method.java:515) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:739) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at dalvik.system.NativeStart.main(Native Method) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:559) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.database.AbstractWindowedCursor.checkPosition (AbstractWindowedCursor.java:172) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.database.AbstractWindowedCursor.getString (AbstractWindowedCursor.java:41) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.database.CursorWrapper.getString(CursorWrapper.java:138) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at com.indigital.IM911.IM911.onActivityResult(IM911.java:516) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.app.Activity.dispatchActivityResult(Activity.java:3415) 04-01 10:01:33.418: ERROR/AndroidRuntime(30289): at android.app.ActivityThread.deliverResults(ActivityThread.java:2836) On Apr 1, 9:52 am, Bobbie wrote: > Any other ideas Boston? Eclipse won't even let me compile that code > without putting it in debug mode, so there is something different in > that code. Could you take another look? Thanks! > > On Mar 31, 5:57 pm, Bobbie wrote: > > > No, I have nothing in onPause(). I guess I'll just have to keep > > playing with it. > > > Bobbie > > > On Mar 31, 4:05 pm, Streets Of Boston wrote: > > > > Do you have code in your 'onPause()' method of your activity. > > > If so, it looks like this code is blocking (never returning). > > > > On Mar 31, 11:39 am, Bobbie wrote: > > > > > When I choose the image, this is what Igetin the debug log: > > > > > 03-31 11:34:36.055: INFO/ActivityManager(55): Displayed activity > > > > com.android.camera/.ImageGallery2: 2455 ms > > > > 03-31 11:34:39.525: VERBOSE/ImageGallery2(11143): / > > > > ImageBlockManager.onPause > > > > 03-31 11:34:49.519: WARN/ActivityManager(55): Launch timeout has > > > > expired, giving up wake lock! > > > > > On Mar 31, 10:24 am, Streets Of Boston > > > > wrote: > > > > > > Did you debug it? > > > > > Did yougeta null-pointer-exception? > > > > > > (The code i gave you may have some issues: I just typed it in, without > > > > > using any IDE such as Eclipse. But it should give you a general idea > > > > > of what to do) > > > > > > On Mar 30, 10:16 pm, Bobbie wrote: > > > > > > > I must have a bad phone or something... Now the program force > > > > > > closes > > > > > > on me? Here's what I have for "onActivityResult." > > > > > > > Cursor cursor = getContentResolver().query(intent.getData(), null, > > > > > > null, null, null); > > > > > > int idx = cursor.getColumnIndex(ImageColumns.DATA); > > > > > > String fname = cursor.getString(idx); > > > > > > > On Mar 30, 9:08 pm, Streets Of Boston > > > > > > wrote: > > > > > > > > int idx = cursor.getColumnIndex(ImageColumn.DATA); > > > > > > > String fname = cursor.getString(idx); > > > > > > > > On Mar 30, 7:45 pm, Bobbie wrote: > > > > > > > > > Wow... It's so simple, but still got an error... I got this:
[android-developers] Re: Photo Picker
Any other ideas Boston? Eclipse won't even let me compile that code without putting it in debug mode, so there is something different in that code. Could you take another look? Thanks! On Mar 31, 5:57 pm, Bobbie wrote: > No, I have nothing in onPause(). I guess I'll just have to keep > playing with it. > > Bobbie > > On Mar 31, 4:05 pm, Streets Of Boston wrote: > > > Do you have code in your 'onPause()' method of your activity. > > If so, it looks like this code is blocking (never returning). > > > On Mar 31, 11:39 am, Bobbie wrote: > > > > When I choose the image, this is what Igetin the debug log: > > > > 03-31 11:34:36.055: INFO/ActivityManager(55): Displayed activity > > > com.android.camera/.ImageGallery2: 2455 ms > > > 03-31 11:34:39.525: VERBOSE/ImageGallery2(11143): / > > > ImageBlockManager.onPause > > > 03-31 11:34:49.519: WARN/ActivityManager(55): Launch timeout has > > > expired, giving up wake lock! > > > > On Mar 31, 10:24 am, Streets Of Boston > > > wrote: > > > > > Did you debug it? > > > > Did yougeta null-pointer-exception? > > > > > (The code i gave you may have some issues: I just typed it in, without > > > > using any IDE such as Eclipse. But it should give you a general idea > > > > of what to do) > > > > > On Mar 30, 10:16 pm, Bobbie wrote: > > > > > > I must have a bad phone or something... Now the program force closes > > > > > on me? Here's what I have for "onActivityResult." > > > > > > Cursor cursor = getContentResolver().query(intent.getData(), null, > > > > > null, null, null); > > > > > int idx = cursor.getColumnIndex(ImageColumns.DATA); > > > > > String fname = cursor.getString(idx); > > > > > > On Mar 30, 9:08 pm, Streets Of Boston wrote: > > > > > > > int idx = cursor.getColumnIndex(ImageColumn.DATA); > > > > > > String fname = cursor.getString(idx); > > > > > > > On Mar 30, 7:45 pm, Bobbie wrote: > > > > > > > > Wow... It's so simple, but still got an error... I got this: > > > > > > > > Cursor cursor = getContentResolver().query(datatoget, null, null, > > > > > > > null, null); > > > > > > > String fname = cursor.getString(ImageColumns.DATA); > > > > > > > > It won't let me run the code... "getString" is underlined in red > > > > > > > and > > > > > > > it just wants me to change it to "getLong" but if I do that, it > > > > > > > just > > > > > > > tells me to change it back to "getString" again... Am I doing > > > > > > > something wrong here, or am I that bad at coding Android? > > > > > > > > On Mar 30, 4:37 pm, Streets Of Boston > > > > > > > wrote: > > > > > > > > > This works as designed. > > > > > > > > > The getDataString() is the string of the contentUrithat refers > > > > > > > > to > > > > > > > > theimage. > > > > > > > > If you want the physical filename, do a 'Cursor cursor = > > > > > > > > getContentResolver().query(intent.getData(), null, null, null, > > > > > > > > null)' > > > > > > > > and query the column ImageColumns.DATA on the returned cursor. > > > > > > > > > Thecursor.getString(ImageColumns.DATA) will return the physical > > > > > > > > file- > > > > > > > >pathon your SC-card. > > > > > > > > > On Mar 30, 3:58 pm, Bobbie wrote: > > > > > > > > > > I am having issues with some "photo picker" code that I am > > > > > > > > > using. All > > > > > > > > > of my pictures are stored on an SD card. The SD card is > > > > > > > > > mounted and I > > > > > > > > > can take pictures no problem. However, when I select a > > > > > > > > > picture from > > > > > > > > > the picker and output the location of the file, I shouldget: > > > > > > > > > > "/sdcard/dcim/Camera/FILENAME.jpg" > > > > > > > > > > But instead, Iget: > > > > > > > > > > "content://media/external/images/media/7" > > > > > > > > > > Any ideas what could be causing this? Here is my code, a > > > > > > > > > button > > > > > > > > > invokes the "takePic()" function: > > > > > > > > > > > > > > > > > > > > public void takePic() { > > > > > > > > > Intent photoPickerIntent = new Intent > > > > > > > > > (Intent.ACTION_GET_CONTENT); > > > > > > > > > photoPickerIntent.setType("image/*"); > > > > > > > > > startActivityForResult(photoPickerIntent, 1); > > > > > > > > > } > > > > > > > > > > @Override > > > > > > > > > protected void onActivityResult(int i, int j, Intent > > > > > > > > > intent) { > > > > > > > > > super.onActivityResult(i, j, intent); > > > > > > > > > > textview.append(intent.getDataString()); > > > > > > > > > }- Hide quoted text - > > > > > > > > - Show quoted text -- 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-de
[android-developers] Re: photo picker Uri issue
I can't tell. Debug your code and see which statement throws an exception and see what exception is thrown and note the values of the variables (are some set to null when they shouldn't, for example). On Apr 1, 9:35 am, Bobbie wrote: > I tried this code, and every time it force closes. The Uri object > gives me the Uri, but I can't see why it's failing... Please help!!! > > Uri photoUri = intent.getData(); > Cursor cursor = getContentResolver().query(photoUri, new String[] > {MediaStore.Images.ImageColumns.DATA}, null, null, null); > String absoluteFilePath = cursor.getString(0); > > On Mar 26, 8:57 am, beachy wrote: > > > > > cheers, did not know that about Drawables will use Bitmaps then. > > > Thanks, > > Greg. > > > On Mar 25, 3:23 pm, Streets Of Boston wrote: > > > > This Uri is the logical (not physical) path used by theimagecontent > > > 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 yourimage, 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 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 aimageand 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?- 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: photo picker Uri issue
I tried this code, and every time it force closes. The Uri object gives me the Uri, but I can't see why it's failing... Please help!!! Uri photoUri = intent.getData(); Cursor cursor = getContentResolver().query(photoUri, new String[] {MediaStore.Images.ImageColumns.DATA}, null, null, null); String absoluteFilePath = cursor.getString(0); On Mar 26, 8:57 am, beachy wrote: > cheers, did not know that about Drawables will use Bitmaps then. > > Thanks, > Greg. > > On Mar 25, 3:23 pm, Streets Of Boston wrote: > > > This Uri is the logical (not physical) path used by theimagecontent > > 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 yourimage, 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 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 aimageand 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 -~--~~~~--~~--~--~---
[android-developers] Re: Photo Picker
No, I have nothing in onPause(). I guess I'll just have to keep playing with it. Bobbie On Mar 31, 4:05 pm, Streets Of Boston wrote: > Do you have code in your 'onPause()' method of your activity. > If so, it looks like this code is blocking (never returning). > > On Mar 31, 11:39 am, Bobbie wrote: > > > When I choose the image, this is what I get in the debug log: > > > 03-31 11:34:36.055: INFO/ActivityManager(55): Displayed activity > > com.android.camera/.ImageGallery2: 2455 ms > > 03-31 11:34:39.525: VERBOSE/ImageGallery2(11143): / > > ImageBlockManager.onPause > > 03-31 11:34:49.519: WARN/ActivityManager(55): Launch timeout has > > expired, giving up wake lock! > > > On Mar 31, 10:24 am, Streets Of Boston > > wrote: > > > > Did you debug it? > > > Did you get a null-pointer-exception? > > > > (The code i gave you may have some issues: I just typed it in, without > > > using any IDE such as Eclipse. But it should give you a general idea > > > of what to do) > > > > On Mar 30, 10:16 pm, Bobbie wrote: > > > > > I must have a bad phone or something... Now the program force closes > > > > on me? Here's what I have for "onActivityResult." > > > > > Cursor cursor = getContentResolver().query(intent.getData(), null, > > > > null, null, null); > > > > int idx = cursor.getColumnIndex(ImageColumns.DATA); > > > > String fname = cursor.getString(idx); > > > > > On Mar 30, 9:08 pm, Streets Of Boston wrote: > > > > > > int idx = cursor.getColumnIndex(ImageColumn.DATA); > > > > > String fname = cursor.getString(idx); > > > > > > On Mar 30, 7:45 pm, Bobbie wrote: > > > > > > > Wow... It's so simple, but still got an error... I got this: > > > > > > > Cursor cursor = getContentResolver().query(datatoget, null, null, > > > > > > null, null); > > > > > > String fname = cursor.getString(ImageColumns.DATA); > > > > > > > It won't let me run the code... "getString" is underlined in red and > > > > > > it just wants me to change it to "getLong" but if I do that, it just > > > > > > tells me to change it back to "getString" again... Am I doing > > > > > > something wrong here, or am I that bad at coding Android? > > > > > > > On Mar 30, 4:37 pm, Streets Of Boston > > > > > > wrote: > > > > > > > > This works as designed. > > > > > > > > The getDataString() is the string of the content Uri that refers > > > > > > > to > > > > > > > theimage. > > > > > > > If you want the physical filename, do a 'Cursor cursor = > > > > > > > getContentResolver().query(intent.getData(), null, null, null, > > > > > > > null)' > > > > > > > and query the column ImageColumns.DATA on the returned cursor. > > > > > > > > Thecursor.getString(ImageColumns.DATA) will return the physical > > > > > > > file- > > > > > > > path on your SC-card. > > > > > > > > On Mar 30, 3:58 pm, Bobbie wrote: > > > > > > > > > I am having issues with some "photo picker" code that I am > > > > > > > > using. All > > > > > > > > of my pictures are stored on an SD card. The SD card is > > > > > > > > mounted and I > > > > > > > > can take pictures no problem. However, when I select a picture > > > > > > > > from > > > > > > > > the picker and output the location of the file, I should get: > > > > > > > > > "/sdcard/dcim/Camera/FILENAME.jpg" > > > > > > > > > But instead, I get: > > > > > > > > > "content://media/external/images/media/7" > > > > > > > > > Any ideas what could be causing this? Here is my code, a button > > > > > > > > invokes the "takePic()" function: > > > > > > > > > > > > > > > > > > public void takePic() { > > > > > > > > Intent photoPickerIntent = new Intent > > > > > > > > (Intent.ACTION_GET_CONTENT); > > > > > > > > photoPickerIntent.setType("image/*"); > > > > > > > > startActivityForResult(photoPickerIntent, 1); > > > > > > > > } > > > > > > > > > @Override > > > > > > > > protected void onActivityResult(int i, int j, Intent > > > > > > > > intent) { > > > > > > > > super.onActivityResult(i, j, intent); > > > > > > > > > textview.append(intent.getDataString()); > > > > > > > > }- Hide quoted text - > > > > > > > - Show quoted text -- 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 -~--~~~~--~~--~--~---
[android-developers] Re: Photo Picker
Do you have code in your 'onPause()' method of your activity. If so, it looks like this code is blocking (never returning). On Mar 31, 11:39 am, Bobbie wrote: > When I choose the image, this is what I get in the debug log: > > 03-31 11:34:36.055: INFO/ActivityManager(55): Displayed activity > com.android.camera/.ImageGallery2: 2455 ms > 03-31 11:34:39.525: VERBOSE/ImageGallery2(11143): / > ImageBlockManager.onPause > 03-31 11:34:49.519: WARN/ActivityManager(55): Launch timeout has > expired, giving up wake lock! > > On Mar 31, 10:24 am, Streets Of Boston > wrote: > > > > > Did you debug it? > > Did you get a null-pointer-exception? > > > (The code i gave you may have some issues: I just typed it in, without > > using any IDE such as Eclipse. But it should give you a general idea > > of what to do) > > > On Mar 30, 10:16 pm, Bobbie wrote: > > > > I must have a bad phone or something... Now the program force closes > > > on me? Here's what I have for "onActivityResult." > > > > Cursor cursor = getContentResolver().query(intent.getData(), null, > > > null, null, null); > > > int idx = cursor.getColumnIndex(ImageColumns.DATA); > > > String fname = cursor.getString(idx); > > > > On Mar 30, 9:08 pm, Streets Of Boston wrote: > > > > > int idx = cursor.getColumnIndex(ImageColumn.DATA); > > > > String fname = cursor.getString(idx); > > > > > On Mar 30, 7:45 pm, Bobbie wrote: > > > > > > Wow... It's so simple, but still got an error... I got this: > > > > > > Cursor cursor = getContentResolver().query(datatoget, null, null, > > > > > null, null); > > > > > String fname = cursor.getString(ImageColumns.DATA); > > > > > > It won't let me run the code... "getString" is underlined in red and > > > > > it just wants me to change it to "getLong" but if I do that, it just > > > > > tells me to change it back to "getString" again... Am I doing > > > > > something wrong here, or am I that bad at coding Android? > > > > > > On Mar 30, 4:37 pm, Streets Of Boston wrote: > > > > > > > This works as designed. > > > > > > > The getDataString() is the string of the content Uri that refers to > > > > > > theimage. > > > > > > If you want the physical filename, do a 'Cursor cursor = > > > > > > getContentResolver().query(intent.getData(), null, null, null, > > > > > > null)' > > > > > > and query the column ImageColumns.DATA on the returned cursor. > > > > > > > Thecursor.getString(ImageColumns.DATA) will return the physical > > > > > > file- > > > > > > path on your SC-card. > > > > > > > On Mar 30, 3:58 pm, Bobbie wrote: > > > > > > > > I am having issues with some "photo picker" code that I am using. > > > > > > > All > > > > > > > of my pictures are stored on an SD card. The SD card is mounted > > > > > > > and I > > > > > > > can take pictures no problem. However, when I select a picture > > > > > > > from > > > > > > > the picker and output the location of the file, I should get: > > > > > > > > "/sdcard/dcim/Camera/FILENAME.jpg" > > > > > > > > But instead, I get: > > > > > > > > "content://media/external/images/media/7" > > > > > > > > Any ideas what could be causing this? Here is my code, a button > > > > > > > invokes the "takePic()" function: > > > > > > > > > > > > > > > > public void takePic() { > > > > > > > Intent photoPickerIntent = new Intent > > > > > > > (Intent.ACTION_GET_CONTENT); > > > > > > > photoPickerIntent.setType("image/*"); > > > > > > > startActivityForResult(photoPickerIntent, 1); > > > > > > > } > > > > > > > > @Override > > > > > > > protected void onActivityResult(int i, int j, Intent intent) { > > > > > > > super.onActivityResult(i, j, intent); > > > > > > > > textview.append(intent.getDataString()); > > > > > > > }- Hide quoted text - > > > > > > - Show quoted text -- 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 -~--~~~~--~~--~--~---
[android-developers] Re: Photo Picker
When I choose the image, this is what I get in the debug log: 03-31 11:34:36.055: INFO/ActivityManager(55): Displayed activity com.android.camera/.ImageGallery2: 2455 ms 03-31 11:34:39.525: VERBOSE/ImageGallery2(11143): / ImageBlockManager.onPause 03-31 11:34:49.519: WARN/ActivityManager(55): Launch timeout has expired, giving up wake lock! On Mar 31, 10:24 am, Streets Of Boston wrote: > Did you debug it? > Did you get a null-pointer-exception? > > (The code i gave you may have some issues: I just typed it in, without > using any IDE such as Eclipse. But it should give you a general idea > of what to do) > > On Mar 30, 10:16 pm, Bobbie wrote: > > > I must have a bad phone or something... Now the program force closes > > on me? Here's what I have for "onActivityResult." > > > Cursor cursor = getContentResolver().query(intent.getData(), null, > > null, null, null); > > int idx = cursor.getColumnIndex(ImageColumns.DATA); > > String fname = cursor.getString(idx); > > > On Mar 30, 9:08 pm, Streets Of Boston wrote: > > > > int idx = cursor.getColumnIndex(ImageColumn.DATA); > > > String fname = cursor.getString(idx); > > > > On Mar 30, 7:45 pm, Bobbie wrote: > > > > > Wow... It's so simple, but still got an error... I got this: > > > > > Cursor cursor = getContentResolver().query(datatoget, null, null, > > > > null, null); > > > > String fname = cursor.getString(ImageColumns.DATA); > > > > > It won't let me run the code... "getString" is underlined in red and > > > > it just wants me to change it to "getLong" but if I do that, it just > > > > tells me to change it back to "getString" again... Am I doing > > > > something wrong here, or am I that bad at coding Android? > > > > > On Mar 30, 4:37 pm, Streets Of Boston wrote: > > > > > > This works as designed. > > > > > > The getDataString() is the string of the content Uri that refers to > > > > > theimage. > > > > > If you want the physical filename, do a 'Cursor cursor = > > > > > getContentResolver().query(intent.getData(), null, null, null, null)' > > > > > and query the column ImageColumns.DATA on the returned cursor. > > > > > > Thecursor.getString(ImageColumns.DATA) will return the physical file- > > > > > path on your SC-card. > > > > > > On Mar 30, 3:58 pm, Bobbie wrote: > > > > > > > I am having issues with some "photo picker" code that I am using. > > > > > > All > > > > > > of my pictures are stored on an SD card. The SD card is mounted > > > > > > and I > > > > > > can take pictures no problem. However, when I select a picture from > > > > > > the picker and output the location of the file, I should get: > > > > > > > "/sdcard/dcim/Camera/FILENAME.jpg" > > > > > > > But instead, I get: > > > > > > > "content://media/external/images/media/7" > > > > > > > Any ideas what could be causing this? Here is my code, a button > > > > > > invokes the "takePic()" function: > > > > > > > > > > > > > > public void takePic() { > > > > > > Intent photoPickerIntent = new Intent > > > > > > (Intent.ACTION_GET_CONTENT); > > > > > > photoPickerIntent.setType("image/*"); > > > > > > startActivityForResult(photoPickerIntent, 1); > > > > > > } > > > > > > > @Override > > > > > > protected void onActivityResult(int i, int j, Intent intent) { > > > > > > super.onActivityResult(i, j, intent); > > > > > > > textview.append(intent.getDataString()); > > > > > > }- 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 -~--~~~~--~~--~--~---
[android-developers] Re: Photo Picker
Did you debug it? Did you get a null-pointer-exception? (The code i gave you may have some issues: I just typed it in, without using any IDE such as Eclipse. But it should give you a general idea of what to do) On Mar 30, 10:16 pm, Bobbie wrote: > I must have a bad phone or something... Now the program force closes > on me? Here's what I have for "onActivityResult." > > Cursor cursor = getContentResolver().query(intent.getData(), null, > null, null, null); > int idx = cursor.getColumnIndex(ImageColumns.DATA); > String fname = cursor.getString(idx); > > On Mar 30, 9:08 pm, Streets Of Boston wrote: > > > > > int idx = cursor.getColumnIndex(ImageColumn.DATA); > > String fname = cursor.getString(idx); > > > On Mar 30, 7:45 pm, Bobbie wrote: > > > > Wow... It's so simple, but still got an error... I got this: > > > > Cursor cursor = getContentResolver().query(datatoget, null, null, > > > null, null); > > > String fname = cursor.getString(ImageColumns.DATA); > > > > It won't let me run the code... "getString" is underlined in red and > > > it just wants me to change it to "getLong" but if I do that, it just > > > tells me to change it back to "getString" again... Am I doing > > > something wrong here, or am I that bad at coding Android? > > > > On Mar 30, 4:37 pm, Streets Of Boston wrote: > > > > > This works as designed. > > > > > The getDataString() is the string of the content Uri that refers to > > > > theimage. > > > > If you want the physical filename, do a 'Cursor cursor = > > > > getContentResolver().query(intent.getData(), null, null, null, null)' > > > > and query the column ImageColumns.DATA on the returned cursor. > > > > > Thecursor.getString(ImageColumns.DATA) will return the physical file- > > > > path on your SC-card. > > > > > On Mar 30, 3:58 pm, Bobbie wrote: > > > > > > I am having issues with some "photo picker" code that I am using. All > > > > > of my pictures are stored on an SD card. The SD card is mounted and I > > > > > can take pictures no problem. However, when I select a picture from > > > > > the picker and output the location of the file, I should get: > > > > > > "/sdcard/dcim/Camera/FILENAME.jpg" > > > > > > But instead, I get: > > > > > > "content://media/external/images/media/7" > > > > > > Any ideas what could be causing this? Here is my code, a button > > > > > invokes the "takePic()" function: > > > > > > > > > > > > public void takePic() { > > > > > Intent photoPickerIntent = new Intent > > > > > (Intent.ACTION_GET_CONTENT); > > > > > photoPickerIntent.setType("image/*"); > > > > > startActivityForResult(photoPickerIntent, 1); > > > > > } > > > > > > @Override > > > > > protected void onActivityResult(int i, int j, Intent intent) { > > > > > super.onActivityResult(i, j, intent); > > > > > > textview.append(intent.getDataString()); > > > > > }- 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 -~--~~~~--~~--~--~---
[android-developers] Re: Photo Picker
I must have a bad phone or something... Now the program force closes on me? Here's what I have for "onActivityResult." Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null); int idx = cursor.getColumnIndex(ImageColumns.DATA); String fname = cursor.getString(idx); On Mar 30, 9:08 pm, Streets Of Boston wrote: > int idx = cursor.getColumnIndex(ImageColumn.DATA); > String fname = cursor.getString(idx); > > On Mar 30, 7:45 pm, Bobbie wrote: > > > Wow... It's so simple, but still got an error... I got this: > > > Cursor cursor = getContentResolver().query(datatoget, null, null, > > null, null); > > String fname = cursor.getString(ImageColumns.DATA); > > > It won't let me run the code... "getString" is underlined in red and > > it just wants me to change it to "getLong" but if I do that, it just > > tells me to change it back to "getString" again... Am I doing > > something wrong here, or am I that bad at coding Android? > > > On Mar 30, 4:37 pm, Streets Of Boston wrote: > > > > This works as designed. > > > > The getDataString() is the string of the content Uri that refers to > > > theimage. > > > If you want the physical filename, do a 'Cursor cursor = > > > getContentResolver().query(intent.getData(), null, null, null, null)' > > > and query the column ImageColumns.DATA on the returned cursor. > > > > Thecursor.getString(ImageColumns.DATA) will return the physical file- > > > path on your SC-card. > > > > On Mar 30, 3:58 pm, Bobbie wrote: > > > > > I am having issues with some "photo picker" code that I am using. All > > > > of my pictures are stored on an SD card. The SD card is mounted and I > > > > can take pictures no problem. However, when I select a picture from > > > > the picker and output the location of the file, I should get: > > > > > "/sdcard/dcim/Camera/FILENAME.jpg" > > > > > But instead, I get: > > > > > "content://media/external/images/media/7" > > > > > Any ideas what could be causing this? Here is my code, a button > > > > invokes the "takePic()" function: > > > > > > > > > > public void takePic() { > > > > Intent photoPickerIntent = new Intent > > > > (Intent.ACTION_GET_CONTENT); > > > > photoPickerIntent.setType("image/*"); > > > > startActivityForResult(photoPickerIntent, 1); > > > > } > > > > > @Override > > > > protected void onActivityResult(int i, int j, Intent intent) { > > > > super.onActivityResult(i, j, intent); > > > > > textview.append(intent.getDataString()); > > > > }- 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: Photo Picker
int idx = cursor.getColumnIndex(ImageColumn.DATA); String fname = cursor.getString(idx); On Mar 30, 7:45 pm, Bobbie wrote: > Wow... It's so simple, but still got an error... I got this: > > Cursor cursor = getContentResolver().query(datatoget, null, null, > null, null); > String fname = cursor.getString(ImageColumns.DATA); > > It won't let me run the code... "getString" is underlined in red and > it just wants me to change it to "getLong" but if I do that, it just > tells me to change it back to "getString" again... Am I doing > something wrong here, or am I that bad at coding Android? > > On Mar 30, 4:37 pm, Streets Of Boston wrote: > > > > > This works as designed. > > > The getDataString() is the string of the content Uri that refers to > > theimage. > > If you want the physical filename, do a 'Cursor cursor = > > getContentResolver().query(intent.getData(), null, null, null, null)' > > and query the column ImageColumns.DATA on the returned cursor. > > > Thecursor.getString(ImageColumns.DATA) will return the physical file- > > path on your SC-card. > > > On Mar 30, 3:58 pm, Bobbie wrote: > > > > I am having issues with some "photo picker" code that I am using. All > > > of my pictures are stored on an SD card. The SD card is mounted and I > > > can take pictures no problem. However, when I select a picture from > > > the picker and output the location of the file, I should get: > > > > "/sdcard/dcim/Camera/FILENAME.jpg" > > > > But instead, I get: > > > > "content://media/external/images/media/7" > > > > Any ideas what could be causing this? Here is my code, a button > > > invokes the "takePic()" function: > > > > > > > > public void takePic() { > > > Intent photoPickerIntent = new Intent > > > (Intent.ACTION_GET_CONTENT); > > > photoPickerIntent.setType("image/*"); > > > startActivityForResult(photoPickerIntent, 1); > > > } > > > > @Override > > > protected void onActivityResult(int i, int j, Intent intent) { > > > super.onActivityResult(i, j, intent); > > > > textview.append(intent.getDataString()); > > > }- 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: Photo Picker
Wow... It's so simple, but still got an error... I got this: Cursor cursor = getContentResolver().query(datatoget, null, null, null, null); String fname = cursor.getString(ImageColumns.DATA); It won't let me run the code... "getString" is underlined in red and it just wants me to change it to "getLong" but if I do that, it just tells me to change it back to "getString" again... Am I doing something wrong here, or am I that bad at coding Android? On Mar 30, 4:37 pm, Streets Of Boston wrote: > This works as designed. > > The getDataString() is the string of the content Uri that refers to > theimage. > If you want the physical filename, do a 'Cursor cursor = > getContentResolver().query(intent.getData(), null, null, null, null)' > and query the column ImageColumns.DATA on the returned cursor. > > Thecursor.getString(ImageColumns.DATA) will return the physical file- > path on your SC-card. > > On Mar 30, 3:58 pm, Bobbie wrote: > > > I am having issues with some "photo picker" code that I am using. All > > of my pictures are stored on an SD card. The SD card is mounted and I > > can take pictures no problem. However, when I select a picture from > > the picker and output the location of the file, I should get: > > > "/sdcard/dcim/Camera/FILENAME.jpg" > > > But instead, I get: > > > "content://media/external/images/media/7" > > > Any ideas what could be causing this? Here is my code, a button > > invokes the "takePic()" function: > > > > > > public void takePic() { > > Intent photoPickerIntent = new Intent > > (Intent.ACTION_GET_CONTENT); > > photoPickerIntent.setType("image/*"); > > startActivityForResult(photoPickerIntent, 1); > > } > > > @Override > > protected void onActivityResult(int i, int j, Intent intent) { > > super.onActivityResult(i, j, intent); > > > textview.append(intent.getDataString()); > > } --~--~-~--~~~---~--~~ 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: Photo Picker
This works as designed. The getDataString() is the string of the content Uri that refers to the image. If you want the physical filename, do a 'Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null)' and query the column ImageColumns.DATA on the returned cursor. The cursor.getString(ImageColumns.DATA) will return the physical file- path on your SC-card. On Mar 30, 3:58 pm, Bobbie wrote: > I am having issues with some "photo picker" code that I am using. All > of my pictures are stored on an SD card. The SD card is mounted and I > can take pictures no problem. However, when I select a picture from > the picker and output the location of the file, I should get: > > "/sdcard/dcim/Camera/FILENAME.jpg" > > But instead, I get: > > "content://media/external/images/media/7" > > Any ideas what could be causing this? Here is my code, a button > invokes the "takePic()" function: > > > > public void takePic() { > Intent photoPickerIntent = new Intent > (Intent.ACTION_GET_CONTENT); > photoPickerIntent.setType("image/*"); > startActivityForResult(photoPickerIntent, 1); > } > > @Override > protected void onActivityResult(int i, int j, Intent intent) { > super.onActivityResult(i, j, intent); > > textview.append(intent.getDataString()); > } --~--~-~--~~~---~--~~ 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: photo picker Uri issue
cheers, did not know that about Drawables will use Bitmaps then. Thanks, Greg. On Mar 25, 3:23 pm, Streets Of Boston wrote: > 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 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 -~--~~~~--~~--~--~---
[android-developers] Re: photo picker Uri issue
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 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 -~--~~~~--~~--~--~---