Problem in storing image in MediaStore in Android
<p>I have written a block of code to insert new image to Android device Image gallery through java program, please find the code below,</p>

<pre><code>ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.BUCKET_ID, "test");
values.put(Images.Media.DESCRIPTION, "test Image taken");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
OutputStream outstream;
try {
    outstream = getContentResolver().openOutputStream(uri);
        receivedBitmap.compress(Bitmap.CompressFormat.JPEG, 70, outstream);             
        outstream.close();
        alertDialog.showMessage("Image Stored Successfully", "Media");
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
    } catch (Exception e) {                          
</code></pre>

<p>Image is stored perfectly, but the problem is i could not view the image immediately. I need to switch off and turn it on the device to view the image. Can anyone plese help me to solve this problem?</p>

<p>Edit: Hi Aleadam, Thanks for the replay, pls check my code below</p>

<pre><code> m_pScanner = new MediaScannerConnection(this,
             new MediaScannerConnectionClient() {
                 public void onMediaScannerConnected() {
                     m_pScanner.scanFile(returnUrl, null /*mimeType*/);
                 }

                 public void onScanCompleted(String path, Uri uri) {
                     if (path.equals(returnUrl)) {
                         ImageViewActivity.this.runOnUiThread(new Runnable() {
                             public void run() {

                             }
                         });
                         m_pScanner.disconnect();
                     }
                 }

         });
        m_pScanner.connect();
</code></pre>

<p>It not working for me, it not even connected with the MediaScanner. whether i missed out something.</p>

<p>Thanks
Rajapandian</p>
