I want to run some code every time an Album is added to Android MediaStore db. I guess I need to register my app for an intent but not sure which one. Anyone know?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Close, but you register to listen for changes to the MediaStore content URI. Something like this, for instance, probably implemented in a service:
getContentResolver().registerContentObserver(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true,
new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
Log.d("ScratchService","External Media has been added");
super.onChange(selfChange);
}
}
);
getContentResolver().registerContentObserver(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, true,
new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
Log.d("ScratchService","Internal Media has been added");
super.onChange(selfChange);
}
}
);
This will only tell you when the MediaStore has been changed, it won't tell you what's been added or deleted. For that you'll have to query the MediaStore.
I hope that's of some use.