2012-02-06 100 views
1

我们是否可以对sd卡上的文件设置权限,以便由于该权限,ion用户将无法打开,读取或写入sd卡的文件......我的意思是,如何使用户无法在应用程序表单sd-card上打开该文件的安全性。 我们是否可以阻止用户访问申请表格外的应用程序文件?Android sdcard文件权限

+0

不,你不能这样做 – Saurabh 2012-02-06 06:21:39

+0

不会解决你的问题,更新它。 – JoxTraex 2012-02-06 06:22:53

+0

您不能限制用户访问SD卡文件,但为了安全起见,您可以加密数据。 – Mihir 2012-02-06 06:25:21

回答

2

是的,它可以设置您需要了解文件的权限基本的文件系统 这将对你有所帮助Android使用Linux内核所以相应地使用它

Java,文件权限非常特定于操作系统:* 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. 

在* nix的系统,你可能需要配置有关文件权限的详细指定,例如,设置777但是,Java IO类对它没有现成的方法,但是您可以使用以下肮脏的解决方法:

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

也许你可以按照用户https://stackoverflow.com/users/491978/mihir建议的方法。

我在我的代码中使用这样的:

如果(!IMAGE_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);