2014-03-26 2 views
1

기기를 부팅 할 때 자동으로 시작되는 애플리케이션을 개발 중이며 기기의 메모리에있는 일부 특수 디렉토리를 모니터링해야합니다. FileObservers는 내 코드는 다음과 같습니다기기 부팅시 Android FileObserver를 사용하는 우아한 방법

if (folder == null) 
    throw new FailedExecutionException(
      "Trying to check the limit of a null directory"); 

Log.d(TAG, "Setting a limit for " + folder.getAbsolutePath()); 

if (!folder.isDirectory()) 
    throw new FailedExecutionException(
      "FolderLimit should be checked on directories, " 
        + folder.getAbsolutePath() + " is not a directory"); 

    //Then create the FileObserver... 

나는 그것이 작동 실행하는 장치와이 응용 프로그램을 실행, 파티션이 어디를 탑재하고 나는 그것을 monitorize 수 있습니다 관찰하고있어 폴더가 나는 장치를 다시 부팅 할 때 문제가된다 , 시스템이 파티션을 마운트하기 전에이 코드가 실행되고 폴더로 인식되지 않습니다 :

com.mycompany.android.helpers.util.FailedExecutionException: FolderLimit should be checked on directories, /mnt/sdcard1/mycompany/photo/white_list is not a directory 

물론 while(!created){ attempt() } 일종의 할 수 있지만이 응용 프로그램에 파티션이 이미 탑재되어 있고 시스템이 준비되었음을 알리는 더 우아한 방법이 있는지 물어보고 싶습니다. 내가 쉘에 마운트 실행하면 내가 가진 무엇

은 다음과 같습니다

127|[email protected]:/ # mount | busybox grep sdcard1        
/dev/block/vold/179:4 /mnt/sdcard1 vfat  rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime= 0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0 
tmpfs /mnt/sdcard1/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0 

감사합니다

내가 말을 잊었 편집, 나는이에 대한 Environment.getExternalStorage()를 사용할 수 없습니다, 그것은 수정 된 장치이며 이것은 릴리스 버전에서 외부 저장소 경로가 될 수있는 파티션이 아닙니다

+2

우아한 솔루션과 Android는 혼합되지 않습니다. – m0skit0

답변

1

마지막으로 나는 무차별 대장 ...

private void attemptToCreateFolderLimit(final File file, 
    final long limitCount, final long recycle) { 

ThreadFactory.startNewThread(TAG, new Runnable() { 

    @Override 
    public void run() { 
    for (int i = 0; i < FOLDER_LIMIT_CREATION_ATTEMPTS; i++) { 
     Log.d(TAG, 
      "creating folder limit for " 
       + file.getAbsoluteFile()); 

     try { 
     FolderLimit limit = new FolderLimit(file, limitCount, 
      recycle); 
     folderLimits.add(limit); 
     } catch (FailedExecutionException e) { 
     Log.e(TAG, "Limit not created"); 
     Log.e(TAG, Log.getStackTraceString(e)); 
     } 
     try { 
     Thread.sleep(FOLDER_LIMIT_TIME_BETWEEN_ATTEMPTS); 
     } catch (InterruptedException e) { 
     Log.e(TAG, Log.getStackTraceString(e)); 
     } 

    } 
    } 
}); 

}