本文介绍了我如何才能知道当一个相册被添加到MediaStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要运行一些code每一个相册添加到Android MediaStore分贝的时间。我想我需要注册我的应用程序为目的,但不知道哪一个。任何人都知道?


解决方案

关闭,但你注册侦听更改MediaStore内容URI。事情是这样的,例如,可能在服务中实现:

<$p$p><$c$c>getContentResolver().registerContentObserver(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,真正,
    新ContentObserver(新处理程序()){
        @覆盖
        公共无效的onChange(布尔selfChange){
            Log.d(ScratchService,外部介质已添加);
            super.onChange(selfChange);
        }
    }
);
getContentResolver().registerContentObserver(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI,真正,
    新ContentObserver(新处理程序()){
        @覆盖
        公共无效的onChange(布尔selfChange){
            Log.d(ScratchService,内部媒体已添加);
            super.onChange(selfChange);
        }
    }
);

这只会告诉你,当MediaStore已经改变,它不会告诉你什么被添加或删除。对于你必须查询MediaStore。

我希望一些使用的。

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?

解决方案

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.

这篇关于我如何才能知道当一个相册被添加到MediaStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 20:15