android - 在图库中删除图像后如何触发广播接收器?
问题描述
我正在开发一个 android 应用程序,该应用程序应该具有从 android 库中删除的图像的副本。如果用户想从图库中删除图片,在他/她删除之前,我们的应用程序必须将图像的副本保存在隐藏文件夹中。我使用了 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
}
解决方案
当文件被删除时,您无法跟踪它。您可以使用文件观察器来跟踪文件夹中的其他内容。
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();
推荐阅读
- javascript - Typescript - 键入一个接受数组的函数,更改其属性之一,但仍返回相同的类型化数组
- c++ - 如何进行无分支数字循环?
- c++ - QGridLayout 小部件设置相等大小
- sql - 如果 count(column) 然后在 Oracle 中选择
- c# - 在 Cefsharp.WPF 中,我应该如何对“fi-FI”(芬兰语)语言进行拼写检查?
- python - 我在 Pygame 中收到一个关于字体的表面错误。我该如何解决?
- str-replace - 使用 str_replace 函数回显错误数据
- javascript - 获取“仅对页面组件执行导出的查询”。在 Gatsby 中尝试生成页面时
- flutter - 使用 Flutter 和 Dart 实现多个过滤器
- laravel - 如何编写更改迁移以在 laravel 中添加复合键