Reputation: 105
Can we set the permission to the files on the sd-card so that because of that permit ion user will not able to open,read or write on sd-card's file... i mean,how to make security that the user will not able to open that files out side the application form sd-card.? can we stop user to access the application's files outside the application form sdcard ??
Upvotes: 1
Views: 3106
Reputation: 1722
yes it it is possible to set file permissions you need to understand basic file systems This Will Be helpfull to you Android uses Linux kernal so use it accordingly
Java, file permissions are very OS specific: *nix , NTFS (windows) and FAT/FAT32, all have different kind of file permissions. Java comes with some generic file permission to deal with it.
Check if the file permission allow :
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.
Set the file permission :
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.
In *nix system, you may need to configure more specifies about file permission, e.g set a 777 permission for a file or directory, however, Java IO classes do not have ready method for it, but you can use the following dirty workaround :
Runtime.getRuntime().exec("chmod 777 file");
Upvotes: 2
Reputation: 5985
Maybe you can follow the approach what user https://stackoverflow.com/users/491978/mihir has suggested.
I have used this in my code:
if (image_url != null && image != 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);
Upvotes: 0