I'm porting an Linux C++ application to Android NDK and my app invokes free
to the shell to see how much memory is available on the machine for logging purposes. On my android port this fails with the error:
sh: free: not found
On a Centos v4 Linux machine, I get back a result like this:
total used free shared buffers cached
Mem: 8308648 3904076 4404572 0 454956 1593844
-/+ buffers/cache: 1855276 6453372
Swap: 2031608 208 2031400
Is there something else I can do here to approximate this on Android?
It seems like it should work:
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
long megAvailable = bytesAvailable / (1024 * 1024);
Log.e("","Available MB : "+megAvailable);
Source: Android-Droid
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.