OPEN源码实例Demo

android.os.FileObserver#OPEN源码实例Demo

下面列出了android.os.FileObserver#OPEN 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: document-viewer   文件: FileSystemScanner.java
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);
    }
}
 
@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;
	}
}
 
源代码3 项目: CameraV   文件: DeviceSucker.java
@Override
public void onEvent(int event, String path) {
    String parse = null;

    switch(event) {
        case FileObserver.CREATE:
            parse = "file created";
            break;
        case FileObserver.MODIFY:
            parse = "file modified";
            break;
        case FileObserver.CLOSE_WRITE:
            parse = "file closed/writen";
            break;
        case FileObserver.ACCESS:
            //parse = "file accessed";
            break;
        case FileObserver.DELETE:
            parse = "file deleted";
            break;
        case FileObserver.OPEN:
            //parse = "file opened";
            break;
        case FileObserver.CLOSE_NOWRITE:
            //parse = "file closed/not writen";
            break;
        case FileObserver.ATTRIB:
            parse = "file attribs changed";
            break;
    }

    if(parse != null) {
        Logger.d(LOG, String.format("EVENT %d ON %s: %s", event, path, parse));
        //lsof_r1(path);

        ILogPack logPack = new ILogPack();
        logPack.put(Keys.FILE_EFFECTED, path);
        logPack.put(Keys.ACCESS_TYPE, parse);
        logPack.put(Keys.ACCESS_CODE, event);

        DeviceSucker.this.sendToBuffer(logPack);
    }
}
 
源代码评论
动弹
沙发等你来抢
 方法所在类