简体   繁体   中英

How to get notifications using Contentresolver

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM