Created
August 8, 2018 18:48
-
-
Save Binary-Finery/d4c23c58caf37c978c37eeff8bdce32e to your computer and use it in GitHub Desktop.
get total RAM and available RAM in megabytes (mb)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.ActivityManager; | |
import android.content.Context; | |
import static android.content.Context.ACTIVITY_SERVICE; | |
public class RAMUtilities { | |
public static long[] getRamInfo(Context context) { | |
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); | |
ActivityManager activityManager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); | |
if (activityManager != null) { | |
activityManager.getMemoryInfo(mi); | |
} | |
return new long[]{ | |
mi.totalMem / 0x100000L, // total ram in mb | |
mi.availMem / 0x100000L // available ram in mb | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment