1

I am using contentresolver to get notifications as follows

@Override
public void onStart(Intent intent, int startid) 
{       
    this.getApplicationContext().getContentResolver().registerContentObserver (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, contentObserver);
    this.getApplicationContext().getContentResolver().registerContentObserver (MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, contentObserver);
    this.getApplicationContext().getContentResolver().registerContentObserver (MediaStore.Video.Media.EXTERNAL_CONTENT_URI, true, contentObserver);
}
private class MyContentObserver extends ContentObserver 
{
@Override
    public void onChange(boolean selfChange) 
    {
       super.onChange(selfChange);
        System.out.println (" Inside Contentobserver onChange" );
    }
}

Here whenever i delete any image/video/audio file from sdcard, after completion of the delete operation that Onchange(bool) is invoking. Is it possible to get the notification before deletion ? I also tried with Broadcastreceiver, but i didn't get any notifications ? thanks in advance

Szymon
  • 42,577
  • 16
  • 96
  • 114
user2791281
  • 149
  • 3
  • 12

1 Answers1

0

No, seems receiving notification before is not possible, because time of notification sending is decided by ContentProvider implementation. If ContentProvdier (especially systems one) sends notification for Uri only after deletion, then You cannot change it get notification earlie.

For example, if You check MediaProvider.delete() source - it become clear that notify get called at the end.

sandrstar
  • 12,503
  • 8
  • 58
  • 65
  • Thanks for replay....But [Dumpster](https://play.google.com/store/apps/details?id=com.baloota.dumpster&hl=en) application is able to get the file and its data before deletion from any third party explorer. Please share your knowledge..thank you – user2791281 Sep 24 '13 at 12:44
  • Hm, I've not used it, but from the description of the App it looks like it's able to 'recover' deleted files, but not ask You 'before' deletion 'are you sure You want to delete smth', right? I'm almost sure it's using smth like http://stackoverflow.com/questions/5891570/monitor-changes-in-a-file-or-directory , but not the way You're considering in the question. Also, checkout this stackoverflow.com/questions/2472582/recovering-the-deleted-data-from-android-sd-card for getting info on how any app possible to restore deleted files from sd card. – sandrstar Sep 25 '13 at 02:13
  • Dumpster is not recovering the deleted files, on delete itself its moving the files into their own location and that is hidden. (like /mnt/sdcard/Android/Data/.com.baloota.Dumpster/Files/.Trash/deleted files). If you delete the files from that location then it won't restore the deleted files. Now my question how they are getting notifications when user is going to delete some file from 3rd party explorer ? – user2791281 Sep 25 '13 at 11:20
  • Have You seen the links, that I've provided in above comments? It shows how to recover deleted files, doesn't it? I'm sure that Your assumptions about notifications from content provider is wrong and You'll not be able to receive notification 'before' and in my answer I've clearly explained why it's not possible. Your approach to solve the problem by receiving notification is just wrong and I'd suggest to try another way and put more efforts and analysis to your problem (because without any code and any particular problem and saying just 'find solution for me' is not the way to ask at SO). – sandrstar Sep 26 '13 at 01:17