0

I am developing an android application where I use androids content provider :-android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI to list the image files. Now I whenever this content provider data gets changed , I want to Toast a message to user. How can I do that.

Please note that I am using androids builtin Content Provide and not my own custom Content Provider.

I don't know but can this thing be solved using notifychange , or getContentResolver.notifyChange.

Thanks

Ankesh kumar Jaisansaria
  • 1,563
  • 4
  • 26
  • 44
  • 2
    I think you can find your answer here http://stackoverflow.com/questions/11237971/how-to-observe-contentprovider-change-android – Hayk Petrosyan May 02 '16 at 09:06
  • @Hayk Petrosyan No, I have gone through this link, but no help – Ankesh kumar Jaisansaria May 02 '16 at 09:07
  • What do you mean "no help"? That's how you do it. – Mike M. May 02 '16 at 09:10
  • I mean that in yhis link its making his own custom content provider – Ankesh kumar Jaisansaria May 02 '16 at 09:12
  • The answer is the same, though, whether it's your Provider, or the platform's. – Mike M. May 02 '16 at 09:14
  • @MikeM. Thanks, I only had this doubt that creating own content provider and using platform's provider would make any difference or not. Now I am able to Toast message to user. Thanks – Ankesh kumar Jaisansaria May 02 '16 at 09:46
  • @Hayk Petrosyan Thanks, I only had this doubt that creating own content provider and using platform's provider would make any difference or not. Now I am able to Toast message to user. Thanks – – Ankesh kumar Jaisansaria May 02 '16 at 09:46
  • @MikeM. But now I have one question that whenever I delete an image file, I get Toast message 4-5 times. This may be mainly because in Content Provider 4-5 different dataset may have got changed. But how to make my app show to user only one toast for an event? – Ankesh kumar Jaisansaria May 02 '16 at 09:48
  • I haven't done anything with the `MediaStore` Provider, but if it's anything like the SMS Provider, it "moves" things just by changing column values in its database, so your Observer is going to fire each time that happens. You'll have to find out which column value change actually means delete, and only act on that one. – Mike M. May 02 '16 at 09:51

1 Answers1

1

Did you add your own ContentObserver class?, I think you need to implement Observable class and handle change event there, than you can show your toasts easily

Hayk Petrosyan
  • 363
  • 1
  • 6