fileobserver

Is IntentService appropriate for FileObserver

☆樱花仙子☆ 提交于 2019-12-08 07:53:34
问题 I need to set a FileObserver on a directory. The observation period is linked to a long running activity, long running because it has a ViewPager with a lot of pages. Instead of placing the FileObserver inside the activity, I was thinking of putting it inside a service. Now I am wondering would I use IntentService or should I roll out my own implementation of Service? My real concern is that I do not want the service to stop until I explicitly call stopService(intent). But I understand that

File observer stops working after some time

醉酒当歌 提交于 2019-12-06 06:27:31
问题 I want to listen to the changes occured in file system.I am using FileObserver.Here is my code: Code: class MyDirObserver extends FileObserver { String superPath; public MyDirObserver(String path) { super(path, ALL_EVENTS); this.superPath = path; } public void onEvent(int event, String path) { Log.e("onEvent of Directory", "=== onEvent ==="); try { _Dump("dir", event, path, superPath); } catch (NullPointerException ex) { Log.e("ERROR", "I am getting error"); } } } private void _Dump(final

How can I get notification of any file being deleted from SD card

天涯浪子 提交于 2019-12-05 05:48:00
I want to create Dumpster like app, for this I want notification when user is deleting any file so that I can save it to my app memory. I used File Observer but it is giving notification after file deletion and in marshmallow it does not notify for deletion also. I referred this link for file observer. Somewhere I read it is possible using native programming language (C), but couldn't get any solution. How can I do this? Thanks in advance. I have tried this: @Override public void onEvent(int event, String path) { if (path == null) { return; } //the monitored file or directory was deleted,

FileObserver instance is being garbage collected

谁说胖子不能爱 提交于 2019-12-05 03:04:33
问题 I need to monitor all files in a folder, when a file opened (FileObserver.OPEN) I want to execute a method. The problem is some times, the FileObserver instance is collected by GC, I tried this: final MyFileObserver fo = new MyFileObserver("/mnt/sdcard/Musicas"); threadFileObserver = new Runnable() { @Override public void run() { fo.startWatching(); } }; t = new Thread(threadFileObserver); t.run(); But is being collected. The question is, what is the best solution for a instance of

File observer stops working after some time

核能气质少年 提交于 2019-12-04 12:23:35
I want to listen to the changes occured in file system.I am using FileObserver.Here is my code: Code: class MyDirObserver extends FileObserver { String superPath; public MyDirObserver(String path) { super(path, ALL_EVENTS); this.superPath = path; } public void onEvent(int event, String path) { Log.e("onEvent of Directory", "=== onEvent ==="); try { _Dump("dir", event, path, superPath); } catch (NullPointerException ex) { Log.e("ERROR", "I am getting error"); } } } private void _Dump(final String tag, int event, String path, String superPath) { Log.d(tag, "=== dump begin ==="); Log.d(tag, "path

How to listen new photos in android?

左心房为你撑大大i 提交于 2019-12-03 15:08:34
I need to listen to new images that comes from any source like downloading images, capture new images, other apps download images..etc Is there any listener that will trigger event whenever new photos is added to gallery? I have been searching for two days. I could not get anything solid. I read about FileObserver , will that help? new photos arrives to gallery means it has been added to the MediaStore . First of all, FileOberver is a memory-killer approach. Consider a high volume of files. Rather ContentObserver seems a far better approach. getContentResolver().registerContentObserver(android

FileObserver CREATE or DELETE received only for files

限于喜欢 提交于 2019-12-03 07:23:15
I've registered a FileObserver for a directory. this.observer = new DirectoryObserver(requested.getAbsolutePath(), FileObserver.CREATE | FileObserver.DELETE | FileObserver.DELETE_SELF); this.observer.startWatching(); Tested on KitKat emulator. adb shell: root@generic:/sdcard # echo "test" >> test.txt //notified CREATE root@generic:/sdcard # rm test.txt //notified DELETE root@generic:/sdcard # mkdir test //no events received root@generic:/sdcard # rmdir test //no events received The DirectoryObserver for reference private final class DirectoryObserver extends FileObserver { private

Receiving Event, if a file was downloaded/ added to download folder

▼魔方 西西 提交于 2019-12-03 05:57:12
问题 I would like to receive an event whenever a file was added to a specific folder, e.g. the download folder. To reach this I tried 3 different approaches without any success. The target devices are Android 15+. Do you have any experience with any of these 3 approaches and could help out with a working sample? APPROACH 1 - FileObserver: In a background service I add a recursive file observer for the top folder as described here. On Android 4/5 its working but on Android 6 no events are fired

FIleObserver and ContentObserver not working in Android Marshmallow

眉间皱痕 提交于 2019-12-01 03:57:20
I have issue with both FIleObserver and ContentObserver not working in Android Marshmallow. I am using this thing for detecting changes that happening inside a folder. I set run time permissions for marshmallow. But after that also it shows no events. It works perfectly in other versions. Please help me to solve this problem. First I tried Content Resolver inside Service for detect folder changes in background. public class TestService extends Service { @Override public void onCreate() { super.onCreate(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { initial();

FileObserver instance is being garbage collected

孤街浪徒 提交于 2019-11-29 05:13:00
I need to monitor all files in a folder, when a file opened (FileObserver.OPEN) I want to execute a method. The problem is some times, the FileObserver instance is collected by GC, I tried this: final MyFileObserver fo = new MyFileObserver("/mnt/sdcard/Musicas"); threadFileObserver = new Runnable() { @Override public void run() { fo.startWatching(); } }; t = new Thread(threadFileObserver); t.run(); But is being collected. The question is, what is the best solution for a instance of FileObserver not be collected? tks!!! I'm guessing the startWatching() method returns immediately, your Thread