File permissions in Android

后端 未结 3 1247
故里飘歌
故里飘歌 2021-01-05 23:48

I\'m here just to ask something maybe very simple, I\'m working with Files, FileOutputStream and FileInputStream, But I just want to get/se

相关标签:
3条回答
  • 2021-01-05 23:59

    There are a couple of issues here:

    1. An application, by default, has unrestricted access to its own files (read/write/delete/'execute'...whatever execute means) but no access to any other application's files.
    2. Android make it difficult to interact with other applications and their data except through Intents. Intents won't work for permissions because you're dependent on the application receiving the Intent to do/provide what you want; they probably weren't designed to tell anybody their files' permissions. There are ways around it, but only when the applications are desgned to operate in the same JVM (i.e. applications you have designed to operate in the same JVM together)

    Your application can get and set permissions for its own files but cannot do that for anyone elses. To my knowledge there is no explicit concept of ownership exposed in the SDK, so you cannot find the owner of a file.

    Android is based on the Linux kernel, but it's not Linux. It's been heavily optimized for running on mobile devices. If you have a machine where an application can only play in its own sandbox you can cut out things like permissions and ownership and get a smaller, faster operating system. The only permissions your files have are the one's you place (and enforce) on them. Other applications' files do not exist.

    0 讨论(0)
  • 2021-01-06 00:20

    Well...if you only want to SEE the permissions couldn't you just use "ls -l" ?

    0 讨论(0)
  • 2021-01-06 00:24

    Android uses the standard Java API for handling files and file permissions. Here's a a page discussing permissions in Java.

    Basically all you need to do is getting the FilePermission object of the file, then getting the PermissionCollection from the FilePermission object with the newPermissionCollection() method and then add or remove items to or from that collection.

    0 讨论(0)
提交回复
热议问题