I have requirement to track any new image file of type .jpg created on device.
I have done this using ContentObserver on MediaStore using below class MediaStoreObserver and,
registering the same in one of my service.
I have noticed that onChange() method gets called many times for a single file creation.
I understand that media file created gets updated in many tables of MediaStore hence onChange() gets called many times.
My question: How to register to MediaStore for ONLY image file create/edit operation ?
-Thanks in advance, Manju
private class MediaStoreObserver extends ContentObserver {
public MediaStoreObserver() {
super(null);
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
//check image file changes in MediaStore
readFromMediaStore(_context,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}
}
//register for external media changes for image files
if(mediaStoreObserver!=null){
_context.getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
false,mediaStoreObserver);