How do we copy files and retain their read only attribute in Android?

陌路散爱 提交于 2019-12-07 12:03:05

问题


In my Android app, I would like to be able to copy a read only file and have the new version also read only.

Using the setReadOnly() method on the destination file only returns false, showing that it failed, and of course checking the file itself shows that it has not had the read only attribute set.

--edit-- As David Given suggests below, this only applies to files on the SD card. Internal files will behave appropriately with setReadOnly().

My manifest file has the line<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> and I'm able to do all sorts of other file operations successfully in my app.

In looking for a solution I've seen a couple of people using linux commands, and they've said that this is a 'dirty' way of doing it, so is there an alternative 'clean' way available to us?

The app I'm writing is using Android 2.1 if that's relevant.


回答1:


I don't believe the SD card supports file attributes like this. I think you can only make files read-only on the internal storage. (Because the SD card uses a FAT file system, but the internal storage uses a proper Linux filesystem.)

Check the result of setReadOnly() and see whether it's returning true or false.



来源:https://stackoverflow.com/questions/9443074/how-do-we-copy-files-and-retain-their-read-only-attribute-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!