Hi,

I just use an activity / service / class  that implements
MediaScannerConnection.MediaScannerConnectionClient

which provides the callback methods -

public void onMediaScannerConnected() {
                // TODO Auto-generated method stub

                bMSCConnected = true;

        }

        public void onScanCompleted(String path, Uri uri) {
                // TODO Auto-generated method stub

                Log.i("ImageService", "onScanCompleted() msc.scanFile() path = "
                                + path + " uri = " + uri.toString());

                mscPath = path;

                mscURI = uri;

                bMSCCompleted = true;

        }


And defines class variables -

MediaScannerConnection msc;

boolean bMSCConnected = false;

etc

And initialises the following in onCreate ( or whatever ) -


msc = new MediaScannerConnection(_context, this);

                if (msc != null) {
                        msc.connect();
                }

and AFTER !!! saving the camera image to the sdcard, I call  -

private void updateMediaScanner(ImageMetaData cgmd) {
                if (bMSCConnected == true) {
                        Log.i("ImageService", "start msc.scanFile() " + 
cgmd.image_path
                                        + cgmd.image_file_name);

                        bMSCCompleted = false;

                        msc.scanFile((cgmd.image_path + cgmd.image_file_name),  
"image/
jpeg");

                        while (bMSCCompleted == false) {
                                try {
                                        Thread.sleep(200);
                                } catch (Exception e) {
                                }
                        }

                        Log.i("ImageService", "end msc.scanFile() mscPath = " + 
mscPath
                                        + " mscURI = " + mscURI.toString());

        }

}

I also call this method from a seperate non UI thread.

In your code I think you need to wait for nMediaScannerConnected() to
be called, before calling scanner.scanFile(picture_path, "image/
jpeg");

And you DO need to save the image to file as I already mentioned ( not
just provide a file name and wait for not to exist - in a while
loop ??? )

Otherwise I suggest you look at the camera source code.

http://android.git.kernel.org/?p=platform/packages/apps/Camera.git;a=commit;h=b104585af4b09f3c7e3dd16eaebb6c96d5064c99

Hope that helps.

Regards

On Jul 6, 6:52 pm, Archana <archana.14n...@gmail.com> wrote:
> I tried like this but still its not working. Can u tell wedr i am
> doing anything wrong.What i have to mention inside
> onMediaScannerConnected()?
>
> File file;
>                         do {
>
>                                 picture_path = "/sdcard/upload" + i++ + 
> ".jpg";
>
>                                 file = new File(picture_path);
>
>                                         MediaScannerConnection scanner = new 
> MediaScannerConnection
> (ImageCapture.this,
>                                                 new 
> MediaScannerConnectionClient() {
>
>                                                         @Override
>                                                         public void 
> onMediaScannerConnected() {
>                                                                 
> System.out.println("Connected"
>                                                                               
>   + (scanner.isConnected()));
>
>                                                         }
>
>                                                         @Override
>                                                         public void 
> onScanCompleted(String path, Uri uri) {
>                                                                 // TODO 
> Auto-generated method stub
>
>                                                         }
>
>                                                 });
>                                 scanner.connect();
>                                 scanner.scanFile(picture_path, "image/jpeg");
>                                 scanner.disconnect();
>                         } while (file.exists());
>
> On Jul 6, 12:40 pm, gjs <garyjamessi...@gmail.com> wrote:
>
> > Hi,
>
> > See android.media.MediaScannerConnection and scanFile(String path,
> > String mimeType)
>
> > Regards
>
> > On Jul 6, 5:00 pm, Archana <archana.14n...@gmail.com> wrote:
>
> > > Hi ,
>
> > >     I am working with camera.. I am facing one problem during
> > > capturingimage.Theimageis not saving directly to gallery.But when i
> > > reboot my device its appearing..
>
> > > Can anybody tell me why this happends.and How can i solve it.
>
> > > Thanks
> > > Archana
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to