java - How to group images in android device according to the folder name? -
i relatively new android. working on gallery application. requirement arrange images in device according folder name. have managed images in folder. not able arrange according folder name. 1 problem facing there may more on folder same name.i attaching code bellow.
final string[] columns = { mediastore.images.media.data, mediastore.images.media._id }; final string orderby = mediastore.images.media._id; bitmap thumbnails[] = new bitmap[3]; string temp = null; int imagecount = 0; cursor imagecursor = context.getcontentresolver().query( mediastore.images.media.external_content_uri, columns, null, null, orderby); int image_column_index = imagecursor .getcolumnindex(mediastore.images.media._id); int count = imagecursor.getcount(); string temparrpath = null; (int = 0; < count; i++) { imagecursor.movetoposition(i); int id = imagecursor.getint(image_column_index); int datacolumnindex = imagecursor .getcolumnindex(mediastore.images.media.data); temparrpath = imagecursor.getstring(datacolumnindex); string[] segments = temparrpath.split("/"); string arrpath = segments[segments.length - 2]; if (arrpath.equals(temp)) { if (imagecount >= 3){ imagecount++; continue; } else { thumbnails[imagecount] = mediastore.images.thumbnails .getthumbnail(getapplicationcontext() .getcontentresolver(), id, mediastore.images.thumbnails.micro_kind, thumbnailoption); imagecount++; } } else { if (i != 0) { log.d(tag, "name = " + temparrpath); adapter.putitem(temp, thumbnails, imagecount); publishprogress(); } imagecount = 0; thumbnails[imagecount] = mediastore.images.thumbnails .getthumbnail(getapplicationcontext() .getcontentresolver(), id, mediastore.images.thumbnails.micro_kind, thumbnailoption); temp = arrpath; imagecount++; } } log.d(tag, "name = " + temparrpath); adapter.putitem(temp, thumbnails, imagecount); publishprogress();
is there other way?
this getting
04-06 23:06:25.080: d/showimagefolder(31250): name = /mnt/sdcard/dcim/opencamera/img_20140212_211241.jpg 04-06 23:06:25.110: d/showimagefolder(31250): name = /mnt/sdcard/download/images.jpg 04-06 23:06:25.150: d/showimagefolder(31250): name = /mnt/sdcard/edited/img_20130810_010215.jpg 04-06 23:06:25.200: d/showimagefolder(31250): name = /mnt/sdcard/noompictures/noompic1382464388594.jpg 04-06 23:06:25.200: d/showimagefolder(31250): name = /mnt/sdcard/dcim/opencamera/img_20140315_202138.jpg 04-06 23:06:25.240: d/showimagefolder(31250): name = /mnt/sdcard/dcim/100andro/dsc_0058.jpg 04-06 23:06:25.280: d/showimagefolder(31250): name = /mnt/sdcard/pictures/telegram/img_20140320_085838_-1044552010.jpg 04-06 23:06:25.320: d/showimagefolder(31250): name = /mnt/sdcard/dcim/opencamera/img_20140330_163630.jpg 04-06 23:06:25.350: d/showimagefolder(31250): name = /mnt/ext_card/wallpapers/boat_autumn-wallpaper-1366x768.jpg 04-06 23:06:25.420: d/showimagefolder(31250): name = /mnt/ext_card/dcim/100andro/dsc_0012.jpg 04-06 23:06:25.480: d/showimagefolder(31250): name = /mnt/ext_card/bluetooth/imag0097.jpg 04-06 23:06:25.500: d/showimagefolder(31250): name = /mnt/sdcard/whatsapp/media/whatsapp images/img-20140331-wa0000.jpg 04-06 23:06:25.560: d/showimagefolder(31250): name = /mnt/sdcard/whatsapp/media/whatsapp images/img-20140406-wa0007.jpg
put temparrpath in treemap. value of key reference adapter.
http://www.mkyong.com/java/how-to-sort-a-map-in-java/
if need name can use treeset , print using comparator: java priorityqueue comparator - how/when sort?
Comments
Post a Comment