android.os.FileObserver Java Examples

The following examples show how to use android.os.FileObserver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileSystemScanner.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
public void stopObservers(final String path) {
    final String mpath = FileUtils.invertMountPrefix(path);
    final String ap = path + "/";
    final String mp = mpath != null ? mpath + "/" : null;

    synchronized (observers) {
        final Iterator<Entry<File, FileObserver>> iter = observers.entrySet().iterator();
        while (iter.hasNext()) {
            final Entry<File, FileObserver> next = iter.next();
            final File file = next.getKey();
            final String filePath = file.getAbsolutePath();
            final boolean eq = filePath.startsWith(ap) || filePath.equals(path) || mpath != null
                    && (filePath.startsWith(mp) || filePath.equals(mpath));
            if (eq) {
                next.getValue().stopWatching();
                iter.remove();
            }
        }
    }
}
 
Example #2
Source File: SettingsProvider.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
void onUserRemoved(int userHandle) {
    synchronized (this) {
        // the db file itself will be deleted automatically, but we need to tear down
        // our caches and other internal bookkeeping.
        FileObserver observer = sObserverInstances.get(userHandle);
        if (observer != null) {
            observer.stopWatching();
            sObserverInstances.delete(userHandle);
        }

        mOpenHelpers.delete(userHandle);
        sSystemCaches.delete(userHandle);
        sSecureCaches.delete(userHandle);
        sKnownMutationsInFlight.delete(userHandle);
        onProfilesChanged();
    }
}
 
Example #3
Source File: FileObservable.java    From RxFileObserver with Apache License 2.0 6 votes vote down vote up
@Override
public void call(final Subscriber<? super FileEvent> subscriber) {
    final FileObserver observer = new FileObserver(pathToWatch) {
        @Override
        public void onEvent(int event, String file) {
            if(subscriber.isUnsubscribed()) {
                return;
            }

            FileEvent fileEvent = FileEvent.create(event, file);
            subscriber.onNext(fileEvent);

            if(fileEvent.isDeleteSelf()) {
                subscriber.onCompleted();
            }
        }
    };
    observer.startWatching(); //START OBSERVING

    subscriber.add(Subscriptions.create(new Action0() {
        @Override
        public void call() {
            observer.stopWatching();
        }
    }));
}
 
Example #4
Source File: MediaListenerService.java    From proofmode with GNU General Public License v3.0 6 votes vote down vote up
private void startWatching() {
    final String pathToWatch = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();

    observer = new RecursiveFileObserver(pathToWatch, FileObserver.CLOSE_WRITE| FileObserver.MOVED_TO) { // set up a file observer to watch this directory on sd card
        @Override
        public void onEvent(int event, final String mediaPath) {
            if (mediaPath != null && (!mediaPath.equals(".probe"))) { // check that it's not equal to .probe because thats created every time camera is launched

                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {

                        if (mediaPath.endsWith(".mp4"))
                            handleNewVideo(mediaPath);
                    }
                });
            }
        }
    };
    observer.startWatching();


}
 
Example #5
Source File: ScreenshotService.java    From Panoramic-Screenshot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(int event, String path) {
	if (event != FileObserver.CREATE) return;
	
	if (path.endsWith(".png")) {
		String file = mScreenshotDir + "/" + path;
		mFiles.add(file);
		
		if (DEBUG) {
			Log.d(TAG, "Adding " + file);
		}
		
		//mIntent.putExtra(EXTRA_PATHS, mFiles.toArray(new String[mFiles.size()]));
		
		PendingIntent i = mFiles.size() >= 2 ? PendingIntent.getActivity(ScreenshotService.this, 0, mIntent, 0) : null;
		
		rebuildNotification(i, String.format(getString(R.string.notifi_count), mFiles.size() + 1), getString(R.string.notifi_tip));
		
		mNotificationManager.notify(R.drawable.ic_launcher, mNotification);
	}
}
 
Example #6
Source File: PrefFileManager.java    From MinMinGuard with GNU General Public License v3.0 6 votes vote down vote up
private PrefFileManager(Context context)
{
    mContext = Build.VERSION.SDK_INT >= 24 && !ContextCompat.isDeviceProtectedStorage(context)
            ? ContextCompat.createDeviceProtectedStorageContext(context) : context;

    mFileObserver = new FileObserver(mContext.getFilesDir().getParentFile() + "/shared_prefs", FileObserver.ATTRIB)
    {
        @Override
        public void onEvent(int event, String path)
        {
            if ((event & FileObserver.ATTRIB) != 0)
                onFileAttributesChanged(path);
        }
    };
    mFileObserver.startWatching();
}
 
Example #7
Source File: FileViewerFragment.java    From SoundRecorder with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(int event, String file) {
    if(event == FileObserver.DELETE){
        // user deletes a recording file out of the app

        String filePath = android.os.Environment.getExternalStorageDirectory().toString()
                + "/SoundRecorder" + file + "]";

        Log.d(LOG_TAG, "File deleted ["
                + android.os.Environment.getExternalStorageDirectory().toString()
                + "/SoundRecorder" + file + "]");

        // remove file from database and recyclerview
        mFileViewerAdapter.removeOutOfApp(filePath);
    }
}
 
Example #8
Source File: PFileIO.java    From PHONK with GNU General Public License v3.0 6 votes vote down vote up
PFileObserver(AppRunner appRunner, String path) {
    fileObserver = new FileObserver(appRunner.getProject().getFullPathForFile(path), FileObserver.CREATE | FileObserver.MODIFY | FileObserver.DELETE) {

        @Override
        public void onEvent(int event, String file) {
            ReturnObject ret = new ReturnObject();
            if ((FileObserver.CREATE & event) != 0) {
                ret.put("action", "created");
            } else if ((FileObserver.DELETE & event) != 0) {
                ret.put("action", "deleted");
            } else if ((FileObserver.MODIFY & event) != 0) {
                ret.put("action", "modified");
            }
            ret.put("file", file);
            if (callback != null) callback.event(ret);
        }

    };
    fileObserver.startWatching();
    getAppRunner().whatIsRunning.add(this);
}
 
Example #9
Source File: PhonkServerService.java    From PHONK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(int event, String file) {
    MLog.d(TAG, "qq -> " + event);
    MLog.d(TAG, "qq2 -> " + file);

    if ((FileObserver.CREATE & event) != 0) {
        MLog.d(TAG, "File created [" + PhonkSettings.getBaseDir() + file + "]");
        EventBus.getDefault().postSticky(new Events.ProjectEvent(Events.PROJECT_REFRESH_LIST, null));
    } else if ((FileObserver.DELETE & event) != 0) {
        MLog.d(TAG, "File deleted [" + PhonkSettings.getBaseDir() + file + "]");
        EventBus.getDefault().postSticky(new Events.ProjectEvent(Events.PROJECT_REFRESH_LIST, null));
    } else if ((FileObserver.MOVED_FROM & event) != 0) {
        MLog.d(TAG, "File moved from [" + PhonkSettings.getBaseDir() + file + "]");
        EventBus.getDefault().postSticky(new Events.ProjectEvent(Events.PROJECT_REFRESH_LIST, null));
    } else if ((FileObserver.MOVED_TO & event) != 0) {
        MLog.d(TAG, "File moved to [" + PhonkSettings.getBaseDir() + file + "]");
        EventBus.getDefault().postSticky(new Events.ProjectEvent(Events.PROJECT_REFRESH_LIST, null));
    }
}
 
Example #10
Source File: PlayListFragment.java    From Android-AudioRecorder-App with Apache License 2.0 6 votes vote down vote up
@Override public void onEvent(int event, String file) {
  if (event == FileObserver.DELETE) {
    // user deletes a recording file out of the app

    String filePath = android.os.Environment.getExternalStorageDirectory().toString()
        + "/SoundRecorder"
        + file
        + "]";

    Log.d(LOG_TAG, "File deleted ["
        + android.os.Environment.getExternalStorageDirectory().toString()
        + "/SoundRecorder"
        + file
        + "]");

    // remove file from database and recyclerview
    mPlayListAdapter.removeOutOfApp(filePath);
  }
}
 
Example #11
Source File: AbstractBrowserFragment.java    From SimpleExplorer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(int event, String path) {
    // this will automatically update the directory when an action like this
    // will be performed
    switch (event & FileObserver.ALL_EVENTS) {
        case FileObserver.CREATE:
        case FileObserver.CLOSE_WRITE:
        case FileObserver.MOVE_SELF:
        case FileObserver.MOVED_TO:
        case FileObserver.MOVED_FROM:
        case FileObserver.ATTRIB:
        case FileObserver.DELETE:
        case FileObserver.DELETE_SELF:
            sHandler.removeCallbacks(mLastRunnable);
            sHandler.post(mLastRunnable =
                    new NavigateRunnable((AbstractBrowserActivity) getActivity(), path));
            break;
    }
}
 
Example #12
Source File: ControlObserver.java    From ClashForMagisk with GNU General Public License v3.0 6 votes vote down vote up
private void restart() {
    //noinspection ResultOfMethodCallIgnored
    dataDir.mkdirs();

    fileObserver = new FileObserver(dataDir.getAbsolutePath(), FileObserver.CREATE | FileObserver.DELETE_SELF | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) {
        @Override
        public void onEvent(int event, String file) {
            Log.d(Constants.TAG, "Control Directory Changed " + file);

            if ((event & FileObserver.DELETE_SELF) != 0) {
                restart();
            } else {
                file = file.toUpperCase();

                switch (file) {
                    case "STOP":
                    case "START":
                    case "RESTART":
                        callback.onUserControl(file);
                }
            }
        }
    };

    fileObserver.startWatching();
}
 
Example #13
Source File: EnvelopeFileObserver.java    From sentry-android with MIT License 6 votes vote down vote up
@Override
public void onEvent(int eventType, @Nullable String relativePath) {
  if (relativePath == null || eventType != FileObserver.CLOSE_WRITE) {
    return;
  }

  logger.log(
      SentryLevel.DEBUG,
      "onEvent fired for EnvelopeFileObserver with event type %d on path: %s for file %s.",
      eventType,
      this.rootPath,
      relativePath);

  // TODO: Only some event types should be pass through?

  final CachedEnvelopeHint hint = new CachedEnvelopeHint(flushTimeoutMillis, logger);
  envelopeSender.processEnvelopeFile(this.rootPath + File.separator + relativePath, hint);
}
 
Example #14
Source File: OfflineVideoManager.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEvent(int event, final String path) {
	if (path == null) {
		return;
	}
	
	switch (event & FileObserver.ALL_EVENTS) {
	case FileObserver.CLOSE_WRITE:
		// Download complete, or paused when wifi is disconnected. Possibly reported more than once in a row.
		// Useful for noticing when a download has been paused. For completions, register a receiver for 
		// DownloadManager.ACTION_DOWNLOAD_COMPLETE.
		break;
	case FileObserver.OPEN:
		// Called for both read and write modes.
		// Useful for noticing a download has been started or resumed.
		break;
	case FileObserver.DELETE:
	case FileObserver.MOVED_FROM:
		// This video is lost never to return. Remove it.
		handler.post(new Runnable() {
			@Override
			public void run() {
				DatabaseHelper helper = dataService.getHelper();
				helper.removeDownloadFromDownloadManager(helper.getVideoForFilename(path));
			}
		});
		break;
	case FileObserver.MODIFY:
		// Called very frequently while a download is ongoing (~1 per ms).
		// This could be used to trigger a progress update, but that should probably be done less often than this.
		shouldPoll = true;
		break;
	}
}
 
Example #15
Source File: FileSystemScanner.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
public void stopObservers() {
    synchronized (observers) {
        for (final FileObserver o : observers.values()) {
            o.stopWatching();
        }
        observers.clear();
    }
}
 
Example #16
Source File: FileSystemScanner.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
public FileObserver getObserver(final File dir) {
    // final String path = dir.getAbsolutePath();
    synchronized (observers) {
        // FileObserver fo = observers.get(path);
        FileObserver fo = observers.get(dir);
        if (fo == null) {
            fo = new FileObserverImpl(dir);
            observers.put(dir, fo);
        }
        return fo;
    }
}
 
Example #17
Source File: RecordingActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void setupFileObserver(File directory) {
    mFileObserver = new FileObserver(directory.getAbsolutePath()) {
        @Override
        public void onEvent(int event, String s) {
            if (s != null && s.equals(mOutputFile.getName()) && event == FileObserver.CLOSE_WRITE) {
                outputFileWrittenLatch.countDown();
            }
        }
    };
    mFileObserver.startWatching();
}
 
Example #18
Source File: FileSystemScanner.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
public static String toString(final int event) {
    switch (event) {
        case FileObserver.ACCESS:
            return "ACCESS";
        case FileObserver.MODIFY:
            return "MODIFY";
        case FileObserver.ATTRIB:
            return "ATTRIB";
        case FileObserver.CLOSE_WRITE:
            return "CLOSE_WRITE";
        case FileObserver.CLOSE_NOWRITE:
            return "CLOSE_NOWRITE";
        case FileObserver.OPEN:
            return "OPEN";
        case FileObserver.MOVED_FROM:
            return "MOVED_FROM";
        case FileObserver.MOVED_TO:
            return "MOVED_TO";
        case FileObserver.CREATE:
            return "CREATE";
        case FileObserver.DELETE:
            return "DELETE";
        case FileObserver.DELETE_SELF:
            return "DELETE_SELF";
        case FileObserver.MOVE_SELF:
            return "MOVE_SELF";
        default:
            return "0x" + Integer.toHexString(event);
    }
}
 
Example #19
Source File: Utils.java    From ploggy with GNU General Public License v3.0 5 votes vote down vote up
public FileInitializedObserver(File directory, String ... filenames) {
    // MOVED_TO is required for the Tor case where the Tor process creates <target>.tmp,
    // writes to that file, then renames to <target>. There's no CLOSE_WRITE event for <target>.
    super(
        directory.getAbsolutePath(),
        FileObserver.MOVED_TO | FileObserver.CLOSE_WRITE);
    mTargetFilenames = new ArrayList<String>(Arrays.asList(filenames));
    mLatch = new CountDownLatch(mTargetFilenames.size());
}
 
Example #20
Source File: RecordingActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private void setupFileObserver(File directory) {
    mFileObserver = new FileObserver(directory.getAbsolutePath()) {
        @Override
        public void onEvent(int event, String s) {
            if (s != null && s.equals(mOutputFile.getName()) && event == FileObserver.CLOSE_WRITE) {
                outputFileWrittenLatch.countDown();
            }
        }
    };
    mFileObserver.startWatching();
}
 
Example #21
Source File: logcat_activity.java    From dingtalk-sms with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onEvent(int event, String path) {
    if (event == FileObserver.MODIFY) {
        runOnUiThread(() -> logcat.setText(public_func.read_log(context)));
    }

}
 
Example #22
Source File: SettingsProvider.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public SettingsFileObserver(int userHandle, String path) {
    super(path, FileObserver.CLOSE_WRITE |
          FileObserver.CREATE | FileObserver.DELETE |
          FileObserver.MOVED_TO | FileObserver.MODIFY);
    mUserHandle = userHandle;
    mPath = path;
}
 
Example #23
Source File: Enhancement.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
private static List<String> getModulesList(final int user) {
    final int index = modulesList.indexOfKey(user);
    if (index >= 0) {
        return modulesList.valueAt(index);
    }

    final String filename = String.format("/data/user_de/%s/%s/conf/enabled_modules.list", user, APPLICATION_ID);
    final FileObserver observer = new FileObserver(filename) {
        @Override
        public void onEvent(int event, @Nullable String path) {
            switch (event) {
                case FileObserver.MODIFY:
                    modulesList.put(user, readModulesList(filename));
                    break;
                case FileObserver.MOVED_FROM:
                case FileObserver.MOVED_TO:
                case FileObserver.MOVE_SELF:
                case FileObserver.DELETE:
                case FileObserver.DELETE_SELF:
                    modulesList.remove(user);
                    modulesListObservers.remove(user);
                    break;
            }
        }
    };
    modulesListObservers.put(user, observer);
    final List<String> list = readModulesList(filename);
    modulesList.put(user, list);
    observer.startWatching();
    return list;
}
 
Example #24
Source File: SDCardListener.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void onEvent(int event, String path) {
    switch(event) {
        case FileObserver.ALL_EVENTS:
            Log.d("all", "path:"+ path);
            break;
        case FileObserver.CREATE:
            Log.d("Create", "path:"+ path);
            break;
    }
}
 
Example #25
Source File: FolderObserver.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Receives and processes events about updates of the monitor folder and its children files.
 * 
 * @param event     Kind of event occurred.
 * @param path      Relative path of the file referred by the event.
 */
@Override
public void onEvent(int event, String path) {
    Log_OC.d(TAG, "Got event " + event + " on FOLDER " + mPath + " about "
            + ((path != null) ? path : ""));
    
    boolean shouldSynchronize = false;
    synchronized(mObservedChildren) {
        if (path != null && path.length() > 0 && mObservedChildren.containsKey(path)) {
            
            if (    ((event & FileObserver.MODIFY) != 0) ||
                    ((event & FileObserver.ATTRIB) != 0) ||
                    ((event & FileObserver.MOVED_TO) != 0) ) {
                
                if (!mObservedChildren.get(path)) {
                    mObservedChildren.put(path, Boolean.valueOf(true));
                }
            }
            
            if ((event & FileObserver.CLOSE_WRITE) != 0 && mObservedChildren.get(path)) {
                mObservedChildren.put(path, Boolean.valueOf(false));
                shouldSynchronize = true;
            }
        }
    }
    if (shouldSynchronize) {
        startSyncOperation(path);
    }
    
    if ((event & IN_IGNORE) != 0 &&
            (path == null || path.length() == 0)) {
        Log_OC.d(TAG, "Stopping the observance on " + mPath);
    }
    
}
 
Example #26
Source File: CameraControlPanel.java    From sandriosCamera with MIT License 5 votes vote down vote up
public void onStartVideoRecord(final File mediaFile) {
    setMediaFilePath(mediaFile);
    if (maxVideoFileSize > 0) {
        recordSizeText.setText("1Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
        recordSizeText.setVisibility(VISIBLE);
        try {
            fileObserver = new FileObserver(this.mediaFilePath) {
                private long lastUpdateSize = 0;

                @Override
                public void onEvent(int event, String path) {
                    final long fileSize = mediaFile.length() / (1024 * 1024);
                    if ((fileSize - lastUpdateSize) >= 1) {
                        lastUpdateSize = fileSize;
                        recordSizeText.post(new Runnable() {
                            @Override
                            public void run() {
                                recordSizeText.setText(fileSize + "Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
                            }
                        });
                    }
                }
            };
            fileObserver.startWatching();
        } catch (Exception e) {
            Log.e("FileObserver", "setMediaFilePath: ", e);
        }
    }
    countDownTimer.start();
}
 
Example #27
Source File: AppRunnerFragment.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void startFileObserver() {

        if (mAppRunner.mIsProjectLoaded) {
            // set up a file observer to watch this directory on sd card
            fileObserver = new FileObserver(mAppRunner.getProject().getFullPath(), FileObserver.CREATE | FileObserver.DELETE) {

                @Override
                public void onEvent(int event, String file) {
                    JSONObject msg = new JSONObject();
                    String action = null;

                    if ((FileObserver.CREATE & event) != 0) {
                        MLog.d(TAG, "created " + file);
                        action = "new_files_in_project";

                    } else if ((FileObserver.DELETE & event) != 0) {
                        MLog.d(TAG, "deleted file " + file);
                        action = "deleted_files_in_project";
                    }

                    try {
                        msg.put("action", action);
                        msg.put("type", "ide");
                        //TODO change to events
                        //IDEcommunication.getInstance(mActivity).send(msg);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                }
            };
        }
    }
 
Example #28
Source File: BaseAnncaFragment.java    From phoenix with Apache License 2.0 4 votes vote down vote up
protected void onStartVideoRecord(final File mediaFile) {
    setMediaFilePath(mediaFile);
    if (maxVideoFileSize > 0) {

        if (cameraFragmentVideoRecordTextListener != null) {
            cameraFragmentVideoRecordTextListener.setRecordSizeText(maxVideoFileSize, "1Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
            cameraFragmentVideoRecordTextListener.setRecordSizeTextVisible(true);
        }
        try {
            fileObserver = new FileObserver(this.mediaFilePath) {
                private long lastUpdateSize = 0;

                @Override
                public void onEvent(int event, String path) {
                    final long fileSize = mediaFile.length() / (1024 * 1024);
                    if ((fileSize - lastUpdateSize) >= 1) {
                        lastUpdateSize = fileSize;
                        new Handler(Looper.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                if (cameraFragmentVideoRecordTextListener != null) {
                                    cameraFragmentVideoRecordTextListener.setRecordSizeText(maxVideoFileSize, fileSize + "Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
                                }
                            }
                        });
                    }
                }
            };
            fileObserver.startWatching();
        } catch (Exception e) {
            Log.e("FileObserver", "setMediaFilePath: ", e);
        }
    }

    if (countDownTimer == null) {
        this.countDownTimer = new TimerTask(timerCallBack);
    }
    countDownTimer.start();

    if (cameraFragmentStateListener != null) {
        cameraFragmentStateListener.onStartVideoRecord(mediaFile);
    }
}
 
Example #29
Source File: DeviceStorageMonitorService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public CacheFileDeletedObserver() {
    super(Environment.getDownloadCacheDirectory().getAbsolutePath(), FileObserver.DELETE);
}
 
Example #30
Source File: MainActivity.java    From open-quartz with Apache License 2.0 4 votes vote down vote up
/**
 * Process picture - from example GDK
 */
private void processPictureWhenReady(final String picturePath) {
    final File pictureFile = new File(picturePath);

    if (pictureFile.exists()) {
        // The picture is ready; process it.
    } else {
        // The file does not exist yet. Before starting the file observer, you
        // can update your UI to let the user know that the application is
        // waiting for the picture (for example, by displaying the thumbnail
        // image and a progress indicator).
        final File parentDirectory = pictureFile.getParentFile();
        final FileObserver observer = new FileObserver(parentDirectory.getPath()) {
            // Protect against additional pending events after CLOSE_WRITE is
            // handled.
            private boolean isFileWritten;

            @Override
            public void onEvent(int event, String path) {
                if (!isFileWritten) {
                    // For safety, make sure that the file that was created in
                    // the directory is actually the one that we're expecting.
                    final File affectedFile = new File(parentDirectory, path);
                    isFileWritten = (event == FileObserver.CLOSE_WRITE
                        && affectedFile.equals(pictureFile));

                    if (isFileWritten) {
                        stopWatching();

                        // Now that the file is ready, recursively call
                        // processPictureWhenReady again (on the UI thread).
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                processPictureWhenReady(picturePath);
                            }
                        });
                    }
                }
            }
        };
        observer.startWatching();
    }
}