I'm using android MediaStore
to get the list of audio files on my music app and these files can be added to playlist. If the file gets deleted from the device memory, the file information need to be deleted from playlist.
Is there any listener/receiver to listen when the audio files are deleted from the device internal/external memory?
I know we can use FileObserver
for any file change. But this required a background service to always run and listen for the file changed. I want to avoid having a service for this. Is there any other way?
Try registering ContentObserver with context.getContentResolver.registerContentObserver(args). I do this in onResume(). get current number of tracks in device memory. I do this in onCreate(). also get current number of tracks in the onchanged method of the ContentObserver in onResume(). If the figures don't match, refresh your current list. You can also register your ContentObserver in service for consistent results. Also don't forget to unregister ContentObserver in onPause() and onDestroy() using context.getContentResolver.unregisterContentObserver(args). works like charm. I will post the code once I retrieve it. Happy coding!