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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -