1

I am trying to figure out a method for finding removable SD cards in Android devices. I have found several methods that provide consistently good results. Sometimes I find two different file paths that seem to point to the exact same position.

For example:

/mnt/sdcard and /storage/sdcard0

appear to point to the same location on some devices. My conclusion is that one of them is an alias, but both can be used to write to the SDcard. I am not too familiar with the use of aliasing, but is there a way to find out if either or both of the files is an alias? Is it possible to determine the "real" file path?

I know that Android is built on a Linux kernal, and has adopted some of the file system conventions. Is there a standard Linux way of doing this?

Jon
  • 1,820
  • 2
  • 19
  • 43

1 Answers1

3

I think you mean symlink.

This is essentially how they do in Apache Commons (subject to their license):

Also mentioned in this answer: Java 1.6 - determine symbolic links

public static boolean isSymlink(File file) throws IOException {
  File canon;
  if (file.getParent() == null) {
    canon = file;
  } else {
    File canonDir = file.getParentFile().getCanonicalFile();
    canon = new File(canonDir, file.getName());
  }
  return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
}
Community
  • 1
  • 1
Timmetje
  • 7,641
  • 18
  • 36
  • Hmm, while you quote the other answer here and link to its source, isn't this a duplicate of Mr.Me's answer? – Sam Mar 14 '13 at 16:14
  • 1
    Nope this is an actual answer to the question. The answer is however a duplicate of many other good answers given to duplicate questions like this. Might this question not be flagged as duplicate (I flagged it) people can still see a right answer. – Timmetje Mar 14 '13 at 16:15