6

I want to know if in android it is possible to create symbolic links from my android application, because I want to create a symbolic link of the folder / data of my application with / sdcard. I am not an expert on android, but I usually do it in java using the Java.nio.File.Files class but in android this class is not allowed, I know that in android there is a way that is by using api 21 with The Os.symlink () method, but this is for android 5.0 and I need it for the minimum android 4.0 or 4.1 onwards. If you know any way please let me know, thank you very much.

Electronicappap
  • 67
  • 1
  • 1
  • 9

2 Answers2

1

Try running it as a command with the Process class.

Process symlink = Runtime.getRuntime().exec("ln -s /path/to/file /path/to/symlink");
Ryan Doherty
  • 140
  • 1
  • 1
  • 9
  • Do not create me in the file link, use your code like this: `try { Process symlink = Runtime.getRuntime().exec("ln -s /sdcard/Enlace.txt /sdcard/Mob/Enlace.txt"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }` – Electronicappap Dec 29 '16 at 17:52
  • 1
    Do not create me in the file link? The hell does that mean? – Ryan Doherty Dec 29 '16 at 18:32
  • Forgive my syntax, what I wanted to say was: is that the link file was not created in the desired directory (it just was not created). Thank you for the correction. – Electronicappap Dec 29 '16 at 19:11
1

It is possible using Os.symlink(originalFilePath, symLinkFilePath) (link here), starting from Lollipop.

If you want to support from older Android versions, check here.

android developer
  • 114,585
  • 152
  • 739
  • 1,270