tags:

views:

61

answers:

1

Hi,

When I run the following line of code:

MediaScannerConnection scanner = new MediaScannerConnection( this, null );
    scanner.connect();
    scanner.scanFile( szFinalFileName, null ); //<---crash here

I get a crash and this message in the console window:

09-26 14:47:44.074: ERROR/MediaScannerService(10288): Failed to delete file /data/data/com.android.providers.media/pause_scan

does anyone have any ideas why this isnt working and what i can do to fix it?

Thanks in advance :-)

A: 

I figured it out.

Here is the code:

final String szFile = szFinalFileName;

            m_pScanner = new MediaScannerConnection(this,
                    new MediaScannerConnectionClient() {
                        public void onMediaScannerConnected() {
                            m_pScanner.scanFile(szFile, null /*mimeType*/);
                        }

                        public void onScanCompleted(String path, Uri uri) {
                            if (path.equals(szFile)) {
                                MugMashView.this.runOnUiThread(new Runnable() {
                                    public void run() {
                                        Toast
                                            .makeText(getApplicationContext(),
                                                "Image now available in Home > Pictures",
                                                Toast.LENGTH_SHORT)
                                            .show();
                                    }
                                });
                                m_pScanner.disconnect();
                            }
                        }

                });
            m_pScanner.connect();
dodobird