How can I notify the gallery of a new image in android?

99封情书 提交于 2019-12-04 02:02:01

问题


I have an android app that allows you to open an image on your phone using an intent to the Gallery. You make modifications to that image and the app saves it with a new name in the same folder the original was in. Since the gallery can't constantly be looking for new images is there any way to notify the gallery of a new image from my android app so it shows up next time the user opens the gallery?


回答1:


use the MediaScannerConnection -

MediaScannerConnection.scanFile(context,
    new String[] { imagePath }, null,
    new MediaScannerConnection.OnScanCompletedListener() {                      
        @Override
        public void onScanCompleted(String path, Uri uri) {
            //....                              
        }
    });



回答2:


As best I can tell from digging through the Android Camera app source, in the ActivityBase.java class there is an inner class called "MyAppBridge" which has the following comment:

//////////////////////////////////////////////////////////////////////////
//  The is the communication interface between the Camera Application and
//  the Gallery PhotoPage.
//////////////////////////////////////////////////////////////////////////

Within that class there is a function as follows:

    public void addSecureAlbumItem(boolean isVideo, int id) {
        if (mServer != null) mServer.addSecureAlbumItem(isVideo, id);
    }

Now the problem is trying to figure out where the Server class comes from, since searching the rest of the project doesn't turn anything up and I can't find it in the imports of the ActivityBase class.

I know this isn't a complete answer but it should hopefully point you in the right direction. When in doubt: Use the source, Luke.



来源:https://stackoverflow.com/questions/19369887/how-can-i-notify-the-gallery-of-a-new-image-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!