Guest User

Untitled

a guest
Jul 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. private class MusicsFileObserver extends FileObserver {
  2.  
  3. public MusicsFileObserver(String root) {
  4. super(root);
  5.  
  6. if (!root.endsWith(File.separator)) {
  7. root += File.separator;
  8. }
  9. }
  10.  
  11. @SuppressWarnings("unused")
  12. public void close() {
  13. super.finalize();
  14. }
  15.  
  16. public void onEvent(final int event, String path) {
  17. //here is the problem, if you see the documentation, when a file is moved
  18. //to this directory, event should be equal to FileObserver.MOVED_TO,
  19. //a constant value of 128. But when debugging, instead of entering here one time
  20. //with event == 128, this method onEvent is being called 4~5 times with event
  21. //with numbers like 1073741656
  22. if (event != FileObserver.ACCESS || event != FileObserver.OPEN || event != 32768)
  23. runOnUiThread(new Runnable() {
  24. public void run() {
  25. rescanMusics();
  26. }
  27. });
  28. }
  29. }
Add Comment
Please, Sign In to add comment