forcing Media Scanner updates

All your problems with Audio, Video and Images.

forcing Media Scanner updates

Postby kraftydevil » Wed Dec 15, 2010 9:13 am

I am writing some jpgs to the sdcard and naming them blindly. In other words I am just naming the files pic1, pic2, pic3, etc.

When I run the app over and over, the files get overwritten, which is my desired result.

The problem is that when I go to view them in the File System, clicking on the pictures loads the old version of pic1/2/3 etc. Oddly enough, the thumbnails have the right picture, but when you click on the picture, another image is loaded.

It looks like this has to do with the media scanner so I'm wondering how to fix this.

Perhaps there is a way to force it to update or another solution?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public void writePicture(Bitmap bmp, String fileName){
  3.                 File pictureFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileName);
  5.                 try{
  6.                         FileOutputStream pfos = new FileOutputStream(pictureFile);
  7.                         bmp.compress(CompressFormat.JPEG, 75, pfos);
  8.                         pfos.flush();
  9.                         pfos.close();
  10.                 }
  11.                 catch (FileNotFoundException e){
  12.                         e.printStackTrace();
  13.                 }
  14.                 catch (IOException e){
  15.                         e.printStackTrace();
  16.                 }
  17.         }
Parsed in 0.013 seconds, using GeSHi
Posts: 3
Joined: Fri Nov 26, 2010 6:24 am


Re: forcing Media Scanner updates

Postby glenandroid » Sat Dec 18, 2010 1:06 pm

Hi Krafty,

I do something similar in one of my applications. The steps are like:

1. creating a media scanner client class -> implements MediaScannerConnection.MediaScannerConnectionClient

2. Establish a connection to the scanner: MediaScannerConnection iConn; iConn = new MediaScannerConnection(context, this);

3. Wait for onMediaScannerConnected() to be called

4. From onMediaScannerConnected() call iConn.scanFile(path, mimeType)

5. wait for onScanComplete() to be called

6. From onScanComplete() call iConn.disconnect()

--> Yes. No. Maybe. I don't know. Can you repeat the question? <--
Junior Developer
Junior Developer
Posts: 16
Joined: Mon Mar 01, 2010 3:40 am
Location: Manchester England


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 4 guests