在图库中删除图像后如何触发广播接收器?

问题描述 投票:0回答:1

我正在开发一个Android应用程序,该应用程序应该具有从android gallery中删除的图像的副本。如果用户想从图库中删除图片,则在删除图片之前,我们的应用必须将图片的副本保存在隐藏的文件夹中。我使用了SMS接收器,但是这有点令人困惑。


       public MyReceiver() {
       }

       @Override
       public void onReceive(Context context, Intent intent) {
            //activity which I want to perform here is to have a copy of deleted image in a hidden folder
       }
android broadcastreceiver android-broadcast
1个回答
0
投票

删除文件后,您无法跟踪它。您可以使用文件查看器来跟踪文件夹中的其他消息。

observer = new FileObserver(Your_folder_Path) { // set up a file observer to watch this directory on sd card

 @Override
 public void onEvent(int event, String file) {
     //if(event == FileObserver.CREATE && !file.equals(".probe")){ // check if its a "create" and not equal to .probe because thats created every time camera is launched
     Log.d(TAG, "File created [" + pathToWatch + file + "]");

     Toast.makeText(getBaseContext(), file + " was saved!", Toast.LENGTH_LONG).show();
     //}
 }
};
 observer.startWatching();
© www.soinside.com 2019 - 2024. All rights reserved.