监控数据库必须继承ContentObserver类; class MusicContentObserver extends ContentObserver{
public MusicContentObserver(Handler handler) { super(handler); }
@Override public void onChange(boolean selfChange) { //数据库变化时 super.onChange(selfChange); ScanSdcardUtils.this.startScanSdcard(); } }
//监听数据库 public void startListenMusic(){ MusicContentObserver musicContentObserver=new MusicContentObserver(new Handler()); mContext.getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, musicContentObserver); }