I have big problems with MediaStore. I need to handle events when MediaStore is changed over MTP. I already have a receiver for android.intent.action.MEDIA_SCANNER_FINISHED
action, but it is useful only for Universal Mass Storage(UMS). The scanner is not launched over MTP, because the MTP changes the MediaStore database directly.
Please would you be so kind and help me how to detect this events. Thank you very much for any help!
I finally found a solution. I tried to use FileObserver but when you use it for all directories...it is quite memory consuming. So now I am using ContentObserver and it is working well:
The flag mRunning has to be there for some reason because onChange was sometimes called even if unregisterContentObserver() had been called before.
This code I am using with Uris that I want to observe, i.e. MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, ...
Create a content observer class
Register the observer in your activity
Don't forget to unregister the observer in onDestroy() function