2012-02-06 4 views
1

허가증 사용자가 SD 카드의 파일을 열거 나 읽거나 쓸 수 없기 때문에 sd- 카드에있는 파일에 대한 사용 권한을 설정할 수 있습니까? 사용자가 응용 프로그램에서 sd-card 형식으로 해당 파일을 열 수 없도록 보안을 설정하십시오. 우리는 사용자가 응용 프로그램 양식 sdcard 외부에서 응용 프로그램의 파일에 액세스하는 것을 중지 할 수 있습니까 ??안드로이드 sdcard 파일 허가

+0

불가능합니다. – Saurabh

+0

질문을 수정하지 않으려 고합니다. – JoxTraex

+0

사용자가 SD 카드 파일에 액세스하는 것을 제한 할 수 없지만 보안을 위해 데이터를 암호화 할 수 있습니다. – Mihir

답변

2

네, 그것은 당신이 이해하는 데 필요한 파일 사용 권한을 설정할 수 있습니다 기본 파일 시스템 이것은 안드로이드가 리눅스 커널을 사용하므로 이에 따라 유용 할 것입니다.

자바 파일 사용 권한은 매우 특정 OS입니다 : * nix, NTFS (windows) 및 FAT/FAT32, 모두 다른 종류의 파일 사용 권한. Java에는이를 처리 할 수있는 일] 파일 권한이 있습니다.

확인 파일 권한을 허용하는 경우 :

file.canExecute(); – return true, file is executable; false is not. 
file.canWrite(); – return true, file is writable; false is not. 
file.canRead(); – return true, file is readable; false is not. 

파일 권한 설정 :

유닉스 계열의 시스템에서
file.setExecutable(boolean); – true, allow execute operations; false to disallow it. 
file.setReadable(boolean); – true, allow read operations; false to disallow it. 
file.setWritable(boolean); – true, allow write operations; false to disallow it. 

, 당신은 예를 들어이 777을 설정, 파일 사용 권한에 대한 자세한 지정을 구성해야 할 수 있습니다를 파일이나 디렉토리에 대한 사용 권한은 있지만 Java IO 클래스에는 준비된 방법이 없지만 다음과 같은 더러운 임시 해결책을 사용할 수 있습니다.

Runtime.getRuntime().exec("chmod 777 file"); 
1

어쩌면 사용자 https://stackoverflow.com/users/491978/mihir이 제안한 접근 방식을 따를 수 있습니다.

내 코드에서 이것을 사용하고 있습니다 :

경우 (! 이미지 URL = null이 & & 이미지 = NULL) {

 Bitmap.CompressFormat image_format; 

     // get image type 
     if (image_url != null && image_url.endsWith("jpg")) { 
      image_format = Bitmap.CompressFormat.JPEG; 
     } else if (image_url != null && image_url.endsWith("png")) { 
      image_format = Bitmap.CompressFormat.PNG; 
     } else { 
      image_format = Bitmap.CompressFormat.JPEG; 
     } 

     File image_cache_file = new File(cache_directory,String.valueOf(image_url.hashCode()) + ".img"); 

     try { 
      FileOutputStream fos = new FileOutputStream(image_cache_file); 

      image.compress(image_format, 100, fos); 

      fos.close(); 

      Log.v(TAG, "Image writen to file with name: " + image_url);