- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我要创建 Dumpster像应用程序一样,为此我希望在用户删除任何文件时收到通知,以便我可以将其保存到我的应用程序内存中。
我使用了 File Observer,但它会在文件删除后发出通知,而在 marshmallow 中,它也不会通知删除。我提到了this link对于文件观察员。我在某处读到可以使用 native 编程语言 (C),但无法获得任何解决方案。我怎样才能做到这一点?提前致谢。
我试过这个:
@Override
public void onEvent(int event, String path) {
if (path == null) {
return;
}
//the monitored file or directory was deleted, monitoring effectively stops
if ((FileObserver.DELETE_SELF & event)!=0) {
FileAccessLogStatic.accessLogMsg += absolutePath + "/" + " is deleted\n";
}
}
最佳答案
让我们先澄清一下。
Handler
使用 service
检查onClick
事件,如果它是一个文件 onClick
,它会将 File
及其 path
保存到一个单独的文件夹中(通常是隐藏的)并将其保存在本地的 database
中。如果它被删除,你知道文件在哪里,如果没有,让我们从那个隐藏文件夹
中删除那个文件。好吧,这有点不值得,因为您几乎需要让您的服务几乎所有时间都在使用 CPU 资源。它也在 Root设备上运行,但为什么根设备仅用于此目的。 随着设备安全性的提高,执行这些任务的可能性越来越小。作为最新的 1-09-2017 所有这些文件回收站 对最新的 android 版本都有负面评论。因此,证明我的观点。
FileObserver
使用检查文件甚至目录的任何更改的概念,但您无法影响它,这意味着您无法阻止删除,它会在用户删除后通知所有内容.
inotify.h
它用于 NDK
创建应用程序,用于检查文件夹和文件上的事件,但如果文件夹提到子子文件夹将不会在此涵盖或通知您文件的任何更改。此外,inotify
中使用的概念与 FileObserver
相同。您只能在文件被删除后收到通知。inotify中使用的代码是这样的。
- Create the inotify instance by
inotify_init
().- Add all the directories to be monitored to the
inotify
list usinginotify_add_watch
() function.- To determine the events occurred, do the read() on the inotify instance. This read will get blocked till the change event occurs. It is recommended to perform selective read on this inotify instance using
select
() call.- Read returns list of events occurred on the monitored directories. Based on the return value of
read
(), we will know exactly what kind of changes occurred.- In case of removing the watch on directories / files, call
inotify_rm_watch
().
inotify 中的两个方法如下:
IN_DELETE
– 从监视目录中删除的文件/目录
IN_DELETE_SELF
– 监视的文件/目录本身已被删除
两者都与 FileObserver
中的几乎相同
此解决方案可能无法完全提供帮助,但仍可帮助创建任何Dumpster 类型的应用程序。可以说,您需要创建自己的 File Manager
,您可以在其中创建自己的自定义 FileV2
(只是一个很酷的名称 File version 2.0)扩展 的类File
并且您可以根据需要覆盖 delete 方法(以及所有其他方法)。您可以创建一个自定义
弹出
,说您是否要删除
您自己的备份
文件在 yes 上 dismissing
在 no 上弹出。 (确保用户使用此文件管理器进行删除,否则它将无法工作,因为覆盖系统文件删除()只会弄乱其他应用程序)。
class filev2 extends File {
public filev2(@NonNull String pathname) {
super(pathname);
}
public filev2(@NonNull URI uri) {
super(uri);
}
@Override
public boolean delete() {
// return super.delete();
//Do as you want and return the boolean.
}
}
但是如果用户为此使用您的文件管理器
,请确保您的文件将被保存。您可以为任务设置 intent-filters
,这样您的 FileManager
就可以进入 ACTION_VIEW
。
最后但我不确定是否也可以使用 registerContentObserver
。 (虽然不确定)
来源:
Linux Help Deleted Log for Files
我希望它对您有所帮助,我希望您现在可以开始做您想要的事情。
关于android - 如何获得从 SD 卡中删除任何文件的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44720696/
我有一个应用程序应该在应用程序处于前台和后台(不在历史记录中)时显示提醒通知。 在前景情况下,我通过以下方法实现了这一点。 PendingIntent pendingIntent = PendingI
如何为我的 WPF 应用程序创建通知,例如浏览器上的通知,它们通过浏览器顶部的“工具栏”显示消息或通过在右下角向上/向下滑动的弹出窗口显示“MSN”样式通知屏幕。也许在应用程序中心淡入/淡出的面板可以
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
我正在使用 Redis 作为分布式缓存。我有不同的应用程序,它们只听特定的键。例如:App1 听 App1.*App2 监听 App2.* 等等。 我的应用程序使用以下模式接收通知:App1:“ ke
我正在尝试构建一个基于官方节点 docker 镜像的 docker 镜像,我想知道是否有某种方法可以在推送新版本的官方节点镜像时自动重建镜像。这样我的图像就不会基于过时的基础图像。 也许有类似 rss
我在一个项目中工作,我需要在添加或修改文件时在数据库中记录文件信息,以便它们保持同步。这些文件应该存储在 Nextcloud 服务器中,那么 Nextcloud 是否有办法通知这些更改(例如 webh
通知类中的方法via 如何根据用户的偏好动态变化,一个用户可能想通过电子邮件接收,而另一个用户则不想 public function via($notifiable) { return ['d
我有一个应用程序,我正在发送推送通知,如果用户登录到应用程序,这很好 - 但是,如果他们没有/如果他们没有在 X 分钟内阅读通知,我想给他们发送一封电子邮件. 我要解决的方法是使用 Laravel N
我正在使用 Django 的 contrib.comments 并想了解以下内容。 是否有任何实用程序或应用程序可以插入到某个应用程序中,当对某个项目发表评论时向您发送通知? 我并没有真正使用过那么多
我希望用户在启动应用程序之前接受协议(protocol)。所以在 appDelegate.m 中我有以下内容: - (BOOL)application:(UIApplication *)applica
我正在创建一个新指令,我想知道如何在 angular 从 DOM 中删除元素时收到通知。 我的目标是在删除元素时添加 jquery 动画。 最佳答案 如果您尝试对元素的移除进行动画处理,则需要在移除元
我正在编写一个应用程序,其工作方式与Apple的Weather.app非常相似:底部有一个UIPageControl,屏幕中间有一个UIScrollView。在我的代码中,我实现了 - (void)s
如何查明 iPhone 注册了哪些通知? 例如: notify_post("com.apple.springboard/Prefs"); 最佳答案 虽然这个问题的答案已经得到确认,但由于 @Nate
我的 Cocoa 应用程序中有一个 TextField。该文本字段有时会被填充,有时会为空。 我希望当字段为空时按钮被禁用。现在,每当我对 Core Data 执行某些操作时,我都会检查该字段,Tex
我的应用程序在其数据库中包含文档。用户可以打开文档,在这种情况下,文档将保存到临时文件夹并在用户计算机上打开。 我希望在这些临时文件之一发生更改时收到通知,并让用户将更改后的文档保存回数据库。 在 D
我目前正在开发一个网络应用程序,它不断对 php 进行 ajax 调用(轮询),以从数据库中提取新的“任务”,有点像 gmail/facebook 检查新电子邮件和消息的方式。当前的 JavaScri
我正在尝试让通知适用于我使用 Angular 5 和 Electron 制作的 Electron 应用程序。到目前为止,我的 index.html 文件中有以下代码: function doNo
我有一个录音/播放应用程序。它在后台运行。当它进入后台时,如果任何其他音频应用程序打开或开始使用音频资源,我想适本地处理我的应用程序。 iOS 提供了一种发送此类通知的方法,如在 ipod 播放器中看
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
是否有 Subversion 的工具可以在对某些文件提交更改时自动通知我? 最佳答案 您可以创建一个 post-commit hook script “ Hook ”提交。 在钩子(Hook)脚本中,
我是一名优秀的程序员,十分优秀!