i want to pick image from Gallery in and copy it in to other Folder in SDCard.
Code to Pick Image from Gallery
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, REQUEST_CODE_CHOOSE_PICTURE_FROM_GALLARY);
i get content://media/external/images/media/681
this URI onActivityResult.
I want to copy the image,
Form path ="content://media/external/images/media/681
To path = "file:///mnt/sdcard/sharedresources/
this path of sdcard in Android.
how to do this?
Hope it will help u
one solution can be,
1) read bytes from inputStream of the picked file.
here you go/
Uri u = Uri.Parse("content://media/external/images/media/681");
Cursor cursor = contentResolver.query(u, null, null, null, null); there is a column name "_data" which will return you the filename, from filename you can create inputstream,
you can now read this input stream
So you have data(byte array) with images byte
2) create a file on to sdcard, and write with byte[] taken in step one.
as fileName you already have from the query method, use same here.
Thanks to all ... Working Code is Here..
Was reading this link, here they are talking about four ways to copy files in Java, so relevant for android as well.
Though author concludes that using 'channel' as used in @Prashant's answer are the best way, you may even explore other ways.
(I have tried first two, and both of them work find)
Even though I have upvoted the answer by @AAnkit, I borrowed and went ahead to modify some items. He mentions to use
Cursor
but without proper illustration it can be confusing to newbies.I think this is simpler than the most voted answer.