java - How to use MediaScannerConnection scanFile? -
i'm downloading image folder on sdcard. since images , folder not visible in gallery i'm trying mediascannerconnection update , show folder/images in gallery. shows how in view code ?
private void downloadimage() { if (future != null) { //set callback , start downloading future.withresponse().setcallback(new futurecallback<response<inputstream>>() { @override public void oncompleted(exception e, response<inputstream> result) { boolean success = false; if (e == null && result != null && result.getresult() != null) { try { //prepare file name string url = mselectedimage.geturl(); string filename = url.substring(url.lastindexof('/') + 1, url.length()); //create temporary directory within cache folder file dir = utils.getalbumstoragedir("wall-tx"); //create file file file = new file(dir, filename); if (!file.exists()) { file.createnewfile(); } //copy image onto file utils.copyinputstreamtofile(result.getresult(), file); //animate first elements animatecompletefirst(true); //broadcast media scanner intent trigger success = true; } catch (exception ex) { log.e("walltx", ex.tostring()); } //animate after complete animatecomplete(success); } else { animatereset(true); } } }); } }
mediascannerconnection.scanfile(this, new string[]{file.getpath()}, null, new mediascannerconnection.onscancompletedlistener() { public void onscancompleted(string path, uri uri) { // visible in gallery } });
Comments
Post a Comment