简体   繁体   English

如何使用Contentresolver获取通知

[英]How to get notifications using Contentresolver

I am using contentresolver to get notifications as follows 我正在使用contentresolver来获取通知,如下所示

@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. 在这里,每当我从sdcard删除任何图像/视频/音频文件时,在完成删除操作后,Onchange(bool)就会调用。 Is it possible to get the notification before deletion ? 是否可以在删除之前获取通知? I also tried with Broadcastreceiver, but i didn't get any notifications ? 我也尝试过Broadcastreceiver,但没有收到任何通知? thanks in advance 提前致谢

No, seems receiving notification before is not possible, because time of notification sending is decided by ContentProvider implementation. 否,似乎不可能提前接收通知,因为通知发送的时间由ContentProvider实现决定。 If ContentProvdier (especially systems one) sends notification for Uri only after deletion, then You cannot change it get notification earlie. 如果ContentProvdier (特别是系统之一)仅在删除后才发送Uri通知,那么您将无法更改它以获取通知。

For example, if You check MediaProvider.delete() source - it become clear that notify get called at the end. 例如,如果您检查MediaProvider.delete()的源,则很明显,通知将在最后被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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