Note that there are some explanatory texts on larger screens.

plurals
  1. POFile Observer is not working from intent service
    primarykey
    data
    text
    <p>I've found a great class to extend the abstract File Observer class...</p> <pre><code>import android.os.FileObserver; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.util.Log; public class FileSync extends FileObserver { public String absolutePath; public String uid; public FileSync(String path, String uidd) { super(path, FileObserver.ALL_EVENTS); absolutePath = path; uid = uidd; } @Override public void onEvent(int event, String path) { if (path == null) { //path is the name of the file... I think its absolute return; } //a new file or subdirectory was created under the monitored directory if ((FileObserver.CREATE &amp; event)!=0) { doFileUpload(path, uid); } //a file or directory was opened if ((FileObserver.OPEN &amp; event)!=0) { //TODO Nothing... yet } //data was read from a file if ((FileObserver.ACCESS &amp; event)!=0) { //TODO Nothing... yet } //data was written to a file if ((FileObserver.MODIFY &amp; event)!=0) { doFileUpload(path,uid); } //someone has a file or directory open read-only, and closed it if ((FileObserver.CLOSE_NOWRITE &amp; event)!=0) { //TODO Nothing... yet } //someone has a file or directory open for writing, and closed it if ((FileObserver.CLOSE_WRITE &amp; event)!=0) { doFileUpload(path,uid); } //[todo: consider combine this one with one below] //a file was deleted from the monitored directory if ((FileObserver.DELETE &amp; event)!=0) { //TODO Remove file from the server } //the monitored file or directory was deleted, monitoring effectively stops if ((FileObserver.DELETE_SELF &amp; event)!=0) { //TODO Toast an error, recreate the folder, resync and restart monitoring } //a file or subdirectory was moved from the monitored directory if ((FileObserver.MOVED_FROM &amp; event)!=0) { //TODO Delete from the server } //a file or subdirectory was moved to the monitored directory if ((FileObserver.MOVED_TO &amp; event)!=0) { doFileUpload(path,uid); } //the monitored file or directory was moved; monitoring continues if ((FileObserver.MOVE_SELF &amp; event)!=0) { //TODO Recreate the folder and show toast } //Metadata (permissions, owner, timestamp) was changed explicitly if ((FileObserver.ATTRIB &amp; event)!=0) { //TODO Nothing... Yet } } </code></pre> <p>I create three of these observers in the onCreate of the IntentService like so:</p> <pre><code>new File("/sdcard/Docs/").mkdir(); FileSync files = new FileSync("/sdcard/Docs/",uid); FileSync pictures = new FileSync(Environment.DIRECTORY_PICTURES,uid); FileSync music = new FileSync(Environment.DIRECTORY_MUSIC,uid); files.startWatching(); pictures.startWatching(); music.startWatching(); </code></pre> <p>Not only are the observers not working, but the mkdir function isn't working.</p> <p>Any ideas? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload