Android application can be installed not only in the folder /data/data/... , but in another place, for example, on a flash drive. How to get the correct path to the folder in which the application is actually installed?
- Why do you need to know this way? You should not edit your application, but you can already read your own files, since they are application resources. - cy6erGn0m
- The lib folder contains libraries that need to be dynamically loaded from another library. - stanislav
|
2 answers
Application folder path (java)
String path = getApplicationInfo().dataDir; But it should be noted that the libraries will not always be in the subfolder lib of the application folder. If the application was installed during the production of the image, apk will be in / system / apps, and so - in / system / lib /.
|
Hmm .. I'm not sure how in the android environment, but just under Linux you can always read / proc / self / exe
#include <stdio.h> static char buffer[4096]; int main(void) { readlink("/proc/self/exe", buffer, sizeof(buffer)); printf("Iam here: %s\n", buffer); return 0; } cy6ergn0m@cgmachine test/cpp/procselfexe $ gcc main.c cy6ergn0m@cgmachine test/cpp/procselfexe $ ./a.out Iam here: /home/cy6ergn0m/test/cpp/procselfexe/a.out cy6ergn0m@cgmachine test/cpp/procselfexe $ After all, cutting off the excess is no longer difficult.
UPD: / proc / self / cwd is not suitable. Here is a good example:
cy6ergn0m@cgmachine test/cpp/procselfexe $ ps ax | grep firefox 15925 pts/5 S+ 0:00 grep --color firefox 23213 ? Sl 474:33 /usr/bin/firefox cy6ergn0m@cgmachine test/cpp/procselfexe $ stat /proc/23213/cwd File: «/proc/23213/cwd» -> «/home/cy6ergn0m/Документы» Size: 0 Blocks: 0 IO Block: 1024 символьная ссылка Device: 3h/3d Inode: 2871843 Links: 1 Access: (0777/lrwxrwxrwx) Uid: (10001/cy6ergn0m) Gid: (10001/cy6ergn0m) Access: 2011-02-01 00:14:16.889605504 +0300 Modify: 2011-02-01 00:14:16.888555587 +0300 Change: 2011-02-01 00:14:16.888555587 +0300 It is clear that firefox does not lie in / home / cy6ergn0m / Documents. It is easy to do a few more checks to finally verify this.
- Why read exe? But using the same approach: / proc / self / cwd / - kirelagin
- cwd? Well, where does cwd refer to? Something I see is that it refers to just the current directory, not the application directory. And what does "exe'shnik" mean to read? Nobody reads it, but it checks where the link leads. - cy6erGn0m
|