Explanation of the Method of Obtaining External SD Sandbox Directory by android ndk Program

  • 2021-10-11 19:34:25
  • OfStack

App of android can only access the directory specified by external SD, and 1 is generally:

$External SD Directory + "/Android/data/" + $apk Package Name

1 To get the external SD directory:

Call the getenv (const char *name) method, which is obtained by the environment variable "SECONDARY_STORAGE", or if there is no such variable, it is obtained by "EXTERNAL_STORAGE".

If the above method does not work, enumerate all directories under the/mnt directory.

2 How to get the apk package name:

pid_t getpid () gets the process identification; Then read the contents of the file/proc/$pid/cmdline to get the process name, which is the package name

3 Piece together sandbox catalog:

$External SD Directory + "/Android/data/" + $apk Package Name + "/cache"


Related articles: