2

i am new to android, i copied files to /storage/sdcard1 from host pc using adb push. But unable to view the file from gallery application.It is showing through ls command and when i rebooted the device , gallery application showing files properly.But immediately it is not updating in gallery , so can any one help me out for this?

Thanks in advance

balu
  • 31
  • 6
  • Are you using any file explorer ? This is related to refreshing data and if you use ES File explorer then you have a refresh button there. Tap it to refresh. – Prateek Jul 24 '14 at 07:03

2 Answers2

1

You'll have to notify the media scanner to capture metadata of the newly created files. Apps like Gallery work on the metadata database and not directly on the filesystem.

Programmatically you'd use MediaScannerConnection.

Since you're working with adb, you can send a broadcast to invoke media scanner.

Media scanner runs as part of the boot sequence so that's why it works after reboot.

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303
0

Because your gallery DB isn't updated.

You can run media scanner manually

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

or Use

MediaStore.Images.Media.insertImage();

You can also insert gallery(media) DB by hand.

private Uri insertMediaStore(String dirPath, String filename, byte[] jpegByteArray) {
    String filePath = dirPath + "/" + filename;

    try {
        ContentValues values = new ContentValues();
        values.put(Images.Media.DATE_TAKEN, new Date().getTime());
        values.put(Images.Media.ORIENTATION, "0");

        String title = filename.replace(".jpg", "");

        values.put(Images.Media.TITLE, title);
        values.put(Images.Media.DISPLAY_NAME, filename);
        values.put(Images.Media.MIME_TYPE, "image/jpeg");
        values.put(Images.Media.SIZE, jpegByteArray.length);
        values.put("_data", filePath);

        Uri uri = getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
        OutputStream os = getContentResolver().openOutputStream(uri);
        os.write(jpegByteArray);
        os.close();

        Logger.info("MediaStore Inserted URI:" + uri.toString());

        return uri;
    } catch(Exception ex) {
        Logger.error(ex, "Failed to save the Bitmap file. FilePath: %s", filePath);
    }

    return null;
}

code reference: http://helloworld.naver.com/helloworld/1819

Chan Lee
  • 303
  • 1
  • 7