android - Gallery thumbnails not visible on Samsung Galaxy S3 -


this driving me nuts, because when create in android picture , save on motorola g, shows ok in gallery. when execute code on samsung galaxy s3, appears folder called "camera" unknown file type.

as can see on pretty-spaghetti-code, create file:

 //insert image , create thumbnail it.  //   // @param cr  //            content resolver use  // @param source  //            stream use image  // @param title  //            name of image  // @param description  //            description of image  // @return url newly created image, or <code>null</code> if   //        image failed stored reason.  // public final string insertimage(contentresolver cr, bitmap source,         string title, string description, long time) {     contentvalues values = new contentvalues();     values.put(images.media.title, title);     values.put(images.media.description, description);     values.put(images.media.mime_type, "image/jpeg");     values.put(images.media.date_taken, time);      string stringurl = null; /* value returned */      outputstream imageout = null;     try {         valpub.url = cr.insert(media.external_content_uri, values);         try {             imageout = cr.openoutputstream(valpub.url);             valpub.strultimafoto = valpub.url.getpath() + "/" + title;         } catch (exception e) {             // esto resuelve el problema de las cámaras samsung             stringurl = valpub.pathsamsung;              file mdir = new file(stringurl);             if (!mdir.exists()) {                 mdir.mkdirs();             }             stringurl = stringurl + title;             valpub.strultimafoto = stringurl;             file m_fil = new file(stringurl);             valpub.url = uri.fromfile(m_fil);             imageout = new fileoutputstream(m_fil);         }         try {             source.compress(bitmap.compressformat.jpeg, 50, imageout);             // bmpfoto = bitmap.createbitmap(source);          } catch (exception e) {         } {             imageout.close();         }          long id=0;         try {             id = contenturis.parseid(valpub.url);         }catch(exception nex) {             cursor mcursorloader;             int mcolumnindex;              // initializing cursorloader             mcursorloader = initializecursorloader();             mcolumnindex = mcursorloader.getcolumnindex(mediastore.images.media._id);              // go thru images in device (external_content_uri)             (int = 0; < mcursorloader.getcount(); i++) {                 mcursorloader.movetoposition(i);                 id = mcursorloader.getint(mcolumnindex);             }          }          // wait until mini_kind thumbnail generated.         bitmap minithumb = null;         try {             minithumb = images.thumbnails.getthumbnail(cr, id,                     images.thumbnails.mini_kind, null);         } catch (exception e) {          }         if (minithumb == null) {             // trick samsung             galleryaddpic(valpub.url);         }         // backward compatibility.         @suppresswarnings("unused")         bitmap microthumb = null;         try {             microthumb = storethumbnail(cr, minithumb, id, 50f, 50f,                     images.thumbnails.micro_kind, title);         } catch (exception e) {         }     } catch (exception e) {}      if (valpub.url != null) {         stringurl = valpub.url.tostring();     }      return stringurl; } 

i tried refresh gallery this:

public void galleryaddpic(uri picuri) {         intent mediascanintent = new intent(intent.action_media_scanner_scan_file, picuri);         sendbroadcast(mediascanintent);     } 

...but didn't worked. seems related asynchronous task, don't know how fix it.

the remaining code:

private cursor initializecursorloader() {         string[] columns = {             mediastore.images.thumbnails._id, mediastore.images.media.data     };      cursorloader cursorloader = new cursorloader(     this, // context     mediastore.images.media.external_content_uri, // uri     columns, // projection     null, // selection     null, // selection args      // sort order: desc = newest first     // sort order: asc = oldest first      mediastore.images.media.date_added + " desc");      // *** note ***     // with:     //     // mediastore.images.media.date_added + " asc"     //     // runs fine (mediastore returns 'null' invalid thumbnails)     // problem seems reside on " desc" tag.     //     // how bizarre that?      return cursorloader.loadinbackground(); }     // public static uri getcontenturi(string volumename) { // return uri.parse("content://mtp/" + volumename + "/video/media"); // }  private final bitmap storethumbnail(contentresolver cr, bitmap source,         long id, float width, float height, int kind, string title) {     // create matrix scale     matrix matrix = new matrix();      float scalex = width / source.getwidth();     float scaley = height / source.getheight();      matrix.setscale(scalex, scaley);      bitmap thumb = bitmap.createbitmap(source, 0, 0, source.getwidth(),             source.getheight(), matrix, true);      contentvalues values = new contentvalues(4);     values.put(images.thumbnails.kind, kind);     values.put(images.thumbnails.image_id, (int) id);     values.put(images.thumbnails.height, thumb.getheight());     values.put(images.thumbnails.width, thumb.getwidth());      valpub.url = cr.insert(images.thumbnails.external_content_uri, values);     if (valpub.url == null) {         valpub.url = cr.insert(media.internal_content_uri, values);     }     outputstream thumbout = null;     try {         thumbout = cr.openoutputstream(valpub.url);     } catch (exception e) {     }     try {         thumb.compress(bitmap.compressformat.jpeg, 100, thumbout);         thumbout.close();         return thumb;     } catch (filenotfoundexception ex) {         return null;     } catch (ioexception ex) {         return null;     } } 

as said before, awful spaghetti code. i'm trying make runnable first , have changed many many times, without luck. please, feel free suggest improvements.

finally, have resolved it. i've changed code in order execute galleryadpic, because refreshes gallery on samsung devices:

public void galleryaddpic(uri picuri) {     intent mediascanintent = new intent(intent.action_media_scanner_scan_file, picuri);     sendbroadcast(mediascanintent); } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -