Reputation: 31
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
Upvotes: 2
Views: 1843
Reputation: 303
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
Upvotes: 0
Reputation: 152807
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.
Upvotes: 1