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
Related
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.
I am developing an app where I load my settings of the app by reading an xml file stored in the external storage. But whenever I reboot the system, I am not able to access the xml for the first time, my app crashes because of this and restarts. from then it can access the xml file. Any clue on whats happening, or what I am doing wrong?
My sample code to open the file:
filepath= Environment.getExternalStorageDirectory().getAbsolutePath();
File file = new File(filepath+"/xy.xml");
Please check if the External Storage is available. Use a broadcast receiver, listen for Intent.ACTION_MEDIA_MOUNTED : Broadcast Action: External media is present and mounted at its mount point.
I want to be notified (via broadcast) when a new file is created on the sdcard in a particular folder.
I can create a service and poll for it, but I would prefer an system event if it exists.
I found it. FileObserver would do it.
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.
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.