3

how can I get the permissions of files listed in eclipse DDMS for android by code. And also the properties like 1). Owner and it's permission like read ,write ,execute 2). Group and it's permission like read ,write ,execute 3). Permissions for others

Thanks in advance.

Moses
  • 916
  • 8
  • 14
  • You can use `ls -l` command in your application with Process. But I think its only works if you have read permission of that directory. Else you need a root permission. – user370305 Nov 26 '12 at 11:47
  • @Ridcully I had a File object with me . I got a normal properties like size, location, mimetype, etc.. I need the owner and group of a file and their respective permissions – Moses Nov 26 '12 at 12:03
  • @user370305 I already rooted my emulator. But I don't know how to get it by code for normal user created files too. – Moses Nov 26 '12 at 12:08
  • see http://stackoverflow.com/questions/3096805/how-do-i-get-the-name-of-a-files-owner-in-java – njzk2 Nov 26 '12 at 12:41

2 Answers2

3
    ProcessBuilder processBuilder = new ProcessBuilder("ls", "-l").directory(new File(file.getParent()));// TODO CHECK IF THE FILE IS SD CARD PARENT IS NULL
  if(BuildConfig.DEBUG)Log.v(TAG, "dir:-"+processBuilder.directory());
  Process process = processBuilder.start();
  PrintWriter out = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));
  BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
  out.flush();
  String resultLine;
  resultLine = in.readLine();
  
  while (resultLine != null) {
      System.out.println(resultLine);
}

The result of the above code will be ,

  • " lrwxrwxrwx root root 2012-12-12 13:34 sdcard "

in this result the first 10 characters are permissions. in that,

  • 2,3,4 characters - shows read,write,execute permission of owner,

  • 5,6,7 characters - shows read,write,execute permission of group,

  • 8,9,10 characters - shows read,write,execute permission of others

    then, owner and group are,

  • 11 to 19 characters - shows owner of the file,

  • 20 to 29 characters - shows group of the file.

Community
  • 1
  • 1
Moses
  • 916
  • 8
  • 14
1

Try this api

http://developer.android.com/reference/android/Manifest.permission.html

ACCESS_CHECKIN_PROPERTIES :Allows read/write access to the "properties" table in the checkin database, to change values that get uploaded.

Okky
  • 10,338
  • 15
  • 75
  • 122
  • 3
    It's not about manifest permissions. It's about file permissions. Thanks for your suggestion. – Moses Dec 12 '12 at 09:44