Android : Monitoring folder activity - android

I want to create an app which would monitor changes to data in a folder on SD card.
For example if a file is put in a folder, as soon as file is copied, my app would send this file to server and delete this file.
Is it possible to do this?
Thanks.

I think you can use android.os.FileObserver which is available since API Level 1.
Source: http://developer.android.com/reference/android/os/FileObserver.html

I looks like there is no system-wide "FileSystemMonitor" you could connect to.
So you have to write it yourself. You could for example receive the ACTION_TIME_TICK broadcast and check the filesystem for changes yourself every minute using the normal java File classes.

Related

Broadcast when user add new file to SDcard

In my cloud backup application i want to upload any image in sdcard immediately create it -
in other words - when user has a new (image) file in his sdcard, (for example, download from whatsapp/email/ added from PC by USB) run a function in my application..
I thought about Broadcast, there is any broadcast who can do it? another way?
You can use android.os.FileObserver:
http://developer.android.com/reference/android/os/FileObserver.html

Changing how android opens files so that it triggers a system service function

Where in AOSP code would I look to add code that triggers a custom system service whenever the user attempts to open a specifically named file?
For example, if a user opens a file on Microsoft Excel on Android, I'm assuming the application is creating a fileinputstream to read in the spreadsheet.
I followed the instructions on http://processors.wiki.ti.com/index.php/Android-Adding_SystemService
All files open by any process are reflected in /proc. I would either modify the procfs to get immediate and full track of such events, or if the requirements allow, retreat to a less penetrating approach, monitoring /proc once in a short while.
See also How do I monitor opened files of a process in realtime?.

how can I input information data when app is in first startup?

I want input data in internal storage of my app when my app installed in new device & never change(delete & update &insert). my information is heavy & if I input my information in oncreate() every time that user open my app information will be make again & I don't like it.how can I do it?
Create a class that is a Broadcastreceiver and register it in your manifest to receiver Intent.ACTION_PACKAGE_INSTALL actions. It will be called only when the application is installed.
You can use assets folder and put your heavy data there. It will be installed with application package. You can find information about that here.

how to run application in background in android?

Hi, I want to make an Android application that continues to run in background and when user accesses any folder, picture, or any other file it notifies using toasts that he accesses this file(filename).
The other people answering your question are focused on the "background" part, and a Service would indeed accomplish this. Users have fairly loudly stated that they despise constantly-running services like the one you are proposing.
when user access any folder or picture or any file it notify using tosts that he acess this file(filename).
For files that you can access yourself (e.g., those on external storage), you can use FileObserver class.
Use FileObserver to detect file access or change.

Shared folder implementation

I need to make a shared folder in android.
I want to be able to:
1) create a folder on the device(sdcard/SharedFolder). ;
2) create a folder on the server. ;
3) copy some files to that folder. ;
4) seamlessly synchronize those files with my Android(and vice-versa). ;
The idea is to make an ftp connection to the ftp server(local filzila server at first) and
compare my local files list to his remote files list(by means of comparing timestamps or any other way).
Then my application would decide which files are the most updated and will copy them(from device to server or from the server to the device).
So i have 3 issues which i wanted to talk about:
I.Currently i made my application be a Broadcast-Receiver which is being called by the Alarm-Manager repeatedly(with the inexact method) and run on its own process.
Upon receiving a broadcast i connect to the server and make the above.
currently the broadcast-receiver is set from some Activity(enable/disable buttons and thats it.)
What will happen to my Broadcast-Receiver after killing the Activity which set him? I understood that at some point the system will delete him from the Alarm-Manager too? How should i handle this? I want the program to run without the user handling it... hence after restart of the device and etc i don't want him to re-enable my program.
II. How would you suggest to handle the files compare between the folders? i would like to support copy, delete, edit on those files hence the most suitable version of a file should be on both the server and device after the sync.
i thought about making some manifest file in each folder and save in it data on the file like:
-who change it last and when
-how much readers does this file have(can it be done as a service of the phone? some event of opening a file or a folder?)
and etc.
III.
Any suggestions will be appreciated!
ADB provides a shell interface where you can issue commands shell commands. See http://developer.android.com/guide/developing/tools/adb.html#shellcommands
You can also use the sync command provided with ADB. Open a prompt and issue 'adb help' to see more.

Categories

Resources