Reputation: 31
My question should be kinda simple but I search a lot from the internet, cannot find the answer.
I could get the path of secondary removable storage(sdcard) with below code
String ExternalSdcardPath = System.getenv("SECONDARY_STORAGE") + "/Sample/";
and I could get path like this , /storage/external_SD/Sample/
and I tried to create file with NDK API ( fopen(ExternalSdcardPath, "a+"); )
but I couldn't create and read file with fopen..
can you please tell me how to create and read file with fopen api in removable path(secondary_storage) ?
Upvotes: 0
Views: 723
Reputation: 1006539
I could get the path of secondary removable storage(sdcard) with below code
There is no requirement for that environment variable to exist, let alone point to something meaningful.
I couldn't create and read file with fopen
You do not have direct filesystem access to arbitrary locations on removable storage on Android 4.4+.
can you please tell me how to create and read file with fopen api in removable path(secondary_storage) ?
Your only places for direct filesystem access to removable storage is in the locations returned by getExternalFilesDirs()
, getExternalCacheDirs()
, and getExternalMediaDirs()
. Those are all methods on Context
(e.g., an activity or service). If they return 2+ values, the second and subsequent ones are on removable storage. Your Java code can supply those paths to your NDK code.
Upvotes: 2