Hi,
I am porting my application to run on Multi-User Environment (Kitkat onwards). My application has a native library which will actually transfer some files to different devices.So, I need to get the path of the file present in sdcard, in Application(Java layer) and pass the path to the native layer which actually opens, reads and sends the file.
In multi-user environment, each user has separate storage path(sdcard) and this is handled by FUSE in the Android Framework. When we get the path of file in sdcard in a new user we get it as /storage/emulated/<user_id>/file.txt in my Application code in Java . But the same path is invalid in the native layer, because native layer can only resolve sdcard path as /mnt/shell/emulated/. Hence file transfer fails.
If we send the path of file as /mnt/shell/emulated/<user-id>/file.txt to native layer, then it can transfer it.
Android provides environment variables like
EMULATED_STORAGE_SOURCE = /storage/emulated/ and
EMULATED_STORAGE_TARGET = /mnt/shell/emulated/
We can get these variables by call System.getenv("EMULATED_STORAGE_SOURCE") and the APIs to get the path getEmulatedStorageSource() is hidden.
The storage path issue can be fixed by replacing EMULATED_STORAGE_SOURCE (/storage/emulated/) with EMULATED_STORAGE_TARGET (/mnt/shell/emulated/) in the sdcard path and then sending the path to native layer.
My question is since the APIs to get above paths are hidden for the developer APIs, is it good practice to use it in my app.(Since it may break my app, if Android framework changes it)
Is there any other solution to fix this storage path issue?