I am saving a few songs in a playlist (in my application database). When a particular song is deleted from the SDCard which already exists in the playlist, how can I reflect the changes in my database?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Look into using a FileObserver
You can monitor either a single file or directory. So what you’ll have to do is determine which directories you have songs in and monitor each. Otherwise you can monitor your external storage directory and then each time anything changes, check if its one of the files in your db.
It works real simple, something like this should work:
Then of course you need to have this FileObserver running at all times for it to be effective so you need to put it in a service. From the service you would do
There are some tricky things to this that you have to keep in mind: