Here are the examples of the java api android.app.ActivityManager.getMemoryInfo() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
77 Examples
19
Source : ProcessManager.java
with Apache License 2.0
from RuijiePan
with Apache License 2.0
from RuijiePan
public long killRunningApp(String processName) {
long beforeMemory = 0;
long endMemory = 0;
mActivityManager.getMemoryInfo(mMemoryInfo);
beforeMemory = mMemoryInfo.availMem;
try {
killBackgroundProcesses(processName);
} catch (Exception e) {
e.printStackTrace();
}
mActivityManager.getMemoryInfo(mMemoryInfo);
endMemory = mMemoryInfo.availMem;
return endMemory - beforeMemory;
}
19
Source : WipeMemoryService.java
with GNU General Public License v3.0
from mollyim
with GNU General Public License v3.0
from mollyim
private long getTotalMemory() {
activityManager.getMemoryInfo(memoryInfo);
return memoryInfo.totalMem;
}
19
Source : WipeMemoryService.java
with GNU General Public License v3.0
from mollyim
with GNU General Public License v3.0
from mollyim
private long getFreeMemory() {
activityManager.getMemoryInfo(memoryInfo);
long freeMem = (long) (memoryInfo.availMem - (memoryInfo.threshold * LOW_MEMORY_THRESHOLD_ADJ));
return (freeMem > 0) ? freeMem : 0;
}
18
Source : PerformanceUtils.java
with Apache License 2.0
from seiginonakama
with Apache License 2.0
from seiginonakama
public static long getFreeMemory() {
ActivityManager am = (ActivityManager) BlockCanaryEx.getConfig().getContext().getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return mi.availMem / 1024;
}
18
Source : MemoryManager.java
with Apache License 2.0
from RuijiePan
with Apache License 2.0
from RuijiePan
public long getAvaliableMemory() {
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
mActivityManager.getMemoryInfo(memoryInfo);
return memoryInfo.availMem;
}
18
Source : VisionProcessorBase.java
with Apache License 2.0
from Rishit-dagli
with Apache License 2.0
from Rishit-dagli
// -----------------Common processing logic-------------------------------------------------------
private Task<T> requestDetectInImage(final InputImage image, final GraphicOverlay graphicOverlay, @Nullable final Bitmap originalCameraImage, boolean shouldShowFps) {
final long startMs = SystemClock.elapsedRealtime();
return detectInImage(image).addOnSuccessListener(executor, results -> {
long currentLatencyMs = SystemClock.elapsedRealtime() - startMs;
numRuns++;
frameProcessedInOneSecondInterval++;
totalRunMs += currentLatencyMs;
maxRunMs = Math.max(currentLatencyMs, maxRunMs);
minRunMs = Math.min(currentLatencyMs, minRunMs);
// Only log inference info once per second. When frameProcessedInOneSecondInterval is
// equal to 1, it means this is the first frame processed during the current second.
if (frameProcessedInOneSecondInterval == 1) {
Log.d(TAG, "Max latency is: " + maxRunMs);
Log.d(TAG, "Min latency is: " + minRunMs);
Log.d(TAG, "Num of Runs: " + numRuns + ", Avg latency is: " + totalRunMs / numRuns);
MemoryInfo mi = new MemoryInfo();
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 0x100000L;
Log.d(TAG, "Memory available in system: " + availableMegs + " MB");
}
graphicOverlay.clear();
if (originalCameraImage != null) {
graphicOverlay.add(new CameraImageGraphic(graphicOverlay, originalCameraImage));
}
VisionProcessorBase.this.onSuccess(results, graphicOverlay);
graphicOverlay.add(new InferenceInfoGraphic(graphicOverlay, currentLatencyMs, shouldShowFps ? framesPerSecond : null));
graphicOverlay.postInvalidate();
}).addOnFailureListener(executor, e -> {
graphicOverlay.clear();
graphicOverlay.postInvalidate();
String error = "Failed to process. Error: " + e.getLocalizedMessage();
Toast.makeText(graphicOverlay.getContext(), error + "\nCause: " + e.getCause(), Toast.LENGTH_SHORT).show();
Log.d(TAG, error);
e.printStackTrace();
VisionProcessorBase.this.onFailure(e);
});
}
18
Source : SysUtils.java
with BSD 3-Clause "New" or "Revised" License
from ridi
with BSD 3-Clause "New" or "Revised" License
from ridi
/**
* @return Whether or not the system has low available memory.
*/
@CalledByNative
public static boolean isCurrentlyLowMemory() {
ActivityManager am = (ActivityManager) ContextUtils.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
am.getMemoryInfo(info);
return info.lowMemory;
}
18
Source : EnvironmentInfo.java
with MIT License
from rakutentech
with MIT License
from rakutentech
private static ActivityManager.MemoryInfo getMemoryInfo(ActivityManager activityManager) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
if (activityManager != null) {
activityManager.getMemoryInfo(mi);
}
return mi;
}
18
Source : LiveInfoDocumentGenerator.java
with Apache License 2.0
from rafaco
with Apache License 2.0
from rafaco
private String getRunningMemory() {
String output = "\n";
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// output += "--> ActivityManager.memoryClreplaced: max ram allowed per app" + "\n";
int memoryClreplaced = manager.getMemoryClreplaced();
output += String.format(" %s Mb allowed per app", memoryClreplaced) + "\n";
// output += "--> ActivityManager.memoryInfo: Total device memory" + "\n";
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
manager.getMemoryInfo(memoryInfo);
long totalMemory1 = -1;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN)
totalMemory1 = memoryInfo.totalMem;
output += String.format(" Device: %s / %s total (%s threshold)%s", Humanizer.parseByte(memoryInfo.availMem), Humanizer.parseByte(totalMemory1), Humanizer.parseByte(memoryInfo.threshold), memoryInfo.lowMemory ? " LOW!" : "") + "\n";
// output += "--> Runtime data: dalvik process" + "\n";
Runtime runtime = Runtime.getRuntime();
int processors = runtime.availableProcessors();
String totalMemory2 = Humanizer.humanReadableByteCount(runtime.totalMemory(), true);
String freeMemory = Humanizer.humanReadableByteCount(runtime.freeMemory(), true);
output += String.format(" Runtime: %s / %s (%s processors) ", freeMemory, totalMemory2, processors) + "\n";
// output += "--> Debug data: system wide" + "\n";
String nativeHeapSize = Humanizer.humanReadableByteCount(Debug.getNativeHeapSize(), true);
// String nativeHeapAllocatedSize = OSInfoDoreplacedentGenerator.humanReadableByteCount(Debug.getNativeHeapAllocatedSize(), true);
String nativeHeapFreeSize = Humanizer.humanReadableByteCount(Debug.getNativeHeapFreeSize(), true);
output += String.format(" NativeHeap: %s / %s", nativeHeapFreeSize, nativeHeapSize) + "\n";
/*
//output += " - Debug.MemoryInfo" + "\n";
Debug.MemoryInfo debugMemoryInfo = new Debug.MemoryInfo();
Debug.getMemoryInfo(debugMemoryInfo);
output += getMemoryInfoFormatted(debugMemoryInfo);
*/
return output;
}
18
Source : SkiaPooledImageRegionDecoder.java
with MIT License
from qunarcorp
with MIT License
from qunarcorp
private boolean isLowMemory() {
ActivityManager activityManager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
if (activityManager != null) {
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
return memoryInfo.lowMemory;
} else {
return true;
}
}
18
Source : CompatibleApps.java
with GNU General Public License v3.0
from NightscoutFoundation
with GNU General Public License v3.0
from NightscoutFoundation
private static void checkMemoryConstraints() {
final ActivityManager actManager = (ActivityManager) xdrip.getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
final ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
final long totalMemory = memInfo.totalMem;
// TODO react to total memory
}
18
Source : MemoryUtil.java
with Apache License 2.0
from Kyson
with Apache License 2.0
from Kyson
public static RamInfo getRamInfo(Context context) {
if (sActivityManager == null) {
sActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
}
final ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
sActivityManager.getMemoryInfo(mi);
final RamInfo ramMemoryInfo = new RamInfo();
ramMemoryInfo.availMemKb = mi.availMem / 1024;
ramMemoryInfo.isLowMemory = mi.lowMemory;
ramMemoryInfo.lowMemThresholdKb = mi.threshold / 1024;
ramMemoryInfo.totalMemKb = getRamTotalMem(sActivityManager);
return ramMemoryInfo;
}
18
Source : MyRenderer.java
with GNU General Public License v3.0
from jsmith613
with GNU General Public License v3.0
from jsmith613
/**
* Return available system memory in bytes
*/
public long availMem() {
_activityManager.getMemoryInfo(_memoryInfo);
return _memoryInfo.availMem;
}
18
Source : ItemListActivity.java
with MIT License
from iamtrk
with MIT License
from iamtrk
public void startApp() {
Content.init(getApplicationContext());
setContentView(R.layout.activity_item_list);
memInfo = (TextView) findViewById(R.id.memory_usage_textView);
cpuInfo = (TextView) findViewById(R.id.cpu_usage_textView);
usageImage = (ImageView) findViewById(R.id.cpu_usage_image);
mgrActivity = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
mgrProcessor = new ProcessorManager();
mgrFrequency = new FrequencyManager();
Double dblPercent = mgrProcessor.getUsage();
String strClock = mgrFrequency.getFrequency();
ActivityManager.MemoryInfo memInformation = new ActivityManager.MemoryInfo();
mgrActivity.getMemoryInfo(memInformation);
long lngFree = memInformation.availMem / 1048576L;
long lngTotal = memInformation.totalMem / 1048576L;
memInfo.setText(Long.valueOf(lngFree).toString() + "MB of" + Long.valueOf(lngTotal).toString() + "MB memory free");
cpuInfo.setText("CPU: " + dblPercent.intValue() + "% @ " + strClock);
usageImage.setImageResource(getCpuUsageImage((int) (dblPercent / 10)));
Thread t = new Thread() {
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(1000);
runOnUiThread(new Runnable() {
@Override
public void run() {
ActivityManager.MemoryInfo memInformation = new ActivityManager.MemoryInfo();
mgrActivity.getMemoryInfo(memInformation);
long lngFree = memInformation.availMem / 1048576L;
long lngTotal = memInformation.totalMem / 1048576L;
memInfo.setText(Long.valueOf(lngFree).toString() + "MB of" + Long.valueOf(lngTotal).toString() + "MB memory free");
Double dblPercent = mgrProcessor.getUsage();
String strClock = mgrFrequency.getFrequency();
cpuInfo.setText("CPU: " + dblPercent.intValue() + "% @ " + strClock);
usageImage.setImageResource(getCpuUsageImage((int) (dblPercent / 10)));
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();
if (findViewById(R.id.item_detail_container) != null) {
// The detail container view will be present only in the
// large-screen layouts (res/values-large and
// res/values-sw600dp). If this view is present, then the
// activity should be in two-pane mode.
mTwoPane = true;
// In two-pane mode, list items should be given the
// 'activated' state when touched.
/*((ItemListFragment) getSupportFragmentManager()
.findFragmentById(R.id.item_list))
.setActivateOnItemClick(true);*/
}
// TODO: If exposing deep links into your app, handle intents here.
}
18
Source : EventSender.java
with Apache License 2.0
from growingio
with Apache License 2.0
from growingio
private ActivityManager.MemoryInfo getMemoryInfo() {
ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
return memoryInfo;
}
18
Source : VisionProcessorBase.java
with Apache License 2.0
from googlesamples
with Apache License 2.0
from googlesamples
// -----------------Common processing logic-------------------------------------------------------
private Task<T> requestDetectInImage(final InputImage image, final GraphicOverlay graphicOverlay, @Nullable final Bitmap originalCameraImage, boolean shouldShowFps) {
final long startMs = SystemClock.elapsedRealtime();
return detectInImage(image).addOnSuccessListener(executor, results -> {
long currentLatencyMs = SystemClock.elapsedRealtime() - startMs;
numRuns++;
frameProcessedInOneSecondInterval++;
totalRunMs += currentLatencyMs;
maxRunMs = Math.max(currentLatencyMs, maxRunMs);
minRunMs = Math.min(currentLatencyMs, minRunMs);
// Only log inference info once per second. When frameProcessedInOneSecondInterval is
// equal to 1, it means this is the first frame processed during the current second.
if (frameProcessedInOneSecondInterval == 1) {
Log.d(TAG, "Max latency is: " + maxRunMs);
Log.d(TAG, "Min latency is: " + minRunMs);
Log.d(TAG, "Num of Runs: " + numRuns + ", Avg latency is: " + totalRunMs / numRuns);
MemoryInfo mi = new MemoryInfo();
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 0x100000L;
Log.d(TAG, "Memory available in system: " + availableMegs + " MB");
}
graphicOverlay.clear();
if (originalCameraImage != null) {
graphicOverlay.add(new CameraImageGraphic(graphicOverlay, originalCameraImage));
}
VisionProcessorBase.this.onSuccess(results, graphicOverlay);
graphicOverlay.add(new InferenceInfoGraphic(graphicOverlay, currentLatencyMs, shouldShowFps ? framesPerSecond : null));
graphicOverlay.postInvalidate();
}).addOnFailureListener(executor, e -> {
graphicOverlay.clear();
graphicOverlay.postInvalidate();
String error = "Failed to process. Error: " + e.getLocalizedMessage();
toast.setText(error + "\nCause: " + e.getCause());
toast.show();
Log.d(TAG, error);
e.printStackTrace();
VisionProcessorBase.this.onFailure(e);
});
}
18
Source : DownloadAsyncTask.java
with Apache License 2.0
from FantasyLWX
with Apache License 2.0
from FantasyLWX
/**
* 判断内存是否充足
*
* @param fileSize 文件大小
* @return 充足就返回true,反之返回false
*/
private boolean isMemoryEnough(long fileSize) {
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return fileSize >= mi.availMem;
}
18
Source : PerformanceUtils.java
with Apache License 2.0
from BzCoder
with Apache License 2.0
from BzCoder
public static long getFreeMemory() {
ActivityManager am = (ActivityManager) BlockCanaryInternals.getContext().provideContext().getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return mi.availMem / 1024;
}
17
Source : LoginBootActivity.java
with GNU General Public License v3.0
from zhangneng
with GNU General Public License v3.0
from zhangneng
// 获取可用内存大小
private long getAvailMemory(Context context) {
// 获取android当前可用内存大小
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// mi.availMem; 当前系统的可用内存
// return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
Log.d(TAG, "可用内存---->>>" + mi.availMem / (1024 * 1024));
return mi.availMem / (1024 * 1024);
}
17
Source : MemoryQuery.java
with Apache License 2.0
from Yuloran
with Apache License 2.0
from Yuloran
/**
* Measures the current memory consumption and thresholds of the app, from
* the ActivityManager and Debug.MemoryInfo,
*
* @return HashMap of memory metrics keyed by string labels.
*/
public HashMap queryMemory() {
// Get ActivityManager.MemoryInfo.
int memoryClreplaced = mActivityManager.getMemoryClreplaced();
int largeMemoryClreplaced = mActivityManager.getLargeMemoryClreplaced();
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
mActivityManager.getMemoryInfo(memoryInfo);
long availMem = memoryInfo.availMem / BYTES_IN_MEGABYTE;
long totalMem = memoryInfo.totalMem / BYTES_IN_MEGABYTE;
long threshold = memoryInfo.threshold / BYTES_IN_MEGABYTE;
boolean lowMemory = memoryInfo.lowMemory;
// Get ActivityManager.RunningAppProcessInfo.
ActivityManager.RunningAppProcessInfo info = new ActivityManager.RunningAppProcessInfo();
ActivityManager.getMyMemoryState(info);
// Retrieve a list of all running processes. Get the app PID.
int appPID = Process.myPid();
// Get ActivityManager.getProcessMemoryInfo for the app PID.
long timestamp = SystemClock.elapsedRealtime();
long totalPrivateDirty = 0L;
long totalSharedDirty = 0L;
long totalPSS = 0L;
long nativePSS = 0L;
long dalvikPSS = 0L;
long otherPSS = 0L;
if (appPID != 0) {
int[] pids = new int[1];
pids[0] = appPID;
Debug.MemoryInfo[] memoryInfoArray = mActivityManager.getProcessMemoryInfo(pids);
totalPrivateDirty = memoryInfoArray[0].getTotalPrivateDirty() / BYTES_IN_KILOBYTE;
totalSharedDirty = memoryInfoArray[0].getTotalSharedDirty() / BYTES_IN_KILOBYTE;
totalPSS = memoryInfoArray[0].getTotalPss() / BYTES_IN_KILOBYTE;
nativePSS = memoryInfoArray[0].nativePss / BYTES_IN_KILOBYTE;
dalvikPSS = memoryInfoArray[0].dalvikPss / BYTES_IN_KILOBYTE;
otherPSS = memoryInfoArray[0].otherPss / BYTES_IN_KILOBYTE;
}
HashMap outputData = new HashMap();
outputData.put(KEY_TIMESTAMP, new Long(timestamp));
outputData.put(KEY_MEMORY_AVAILABLE, new Long(availMem));
outputData.put(KEY_TOTAL_MEMORY, new Long(totalMem));
outputData.put(KEY_TOTAL_PSS, new Long(totalPSS));
outputData.put(KEY_LAST_TRIM_LEVEL, new Integer(info.lastTrimLevel));
outputData.put(KEY_TOTAL_PRIVATE_DIRTY, new Long(totalPrivateDirty));
outputData.put(KEY_TOTAL_SHARED_DIRTY, new Long(totalSharedDirty));
outputData.put(KEY_MEMORY_CLreplaced, new Long(memoryClreplaced));
outputData.put(KEY_LARGE_MEMORY_CLreplaced, new Long(largeMemoryClreplaced));
outputData.put(KEY_NATIVE_PSS, new Long(nativePSS));
outputData.put(KEY_DALVIK_PSS, new Long(dalvikPSS));
outputData.put(KEY_OTHER_PSS, new Long(otherPSS));
outputData.put(KEY_THRESHOLD, new Long(threshold));
outputData.put(KEY_LOW_MEMORY, new Boolean(lowMemory));
Log.d(TAG, String.format("timestamp=%d, availMem=%d, totalMem=%d, totalPSS=%d, " + "lastTrimLevel=%d, largeMemoryClreplaced=%d, nativePSS=%d, dalvikPSS=%d, otherPSS=%d," + "threshold=%d, lowMemory=%s", timestamp, availMem, totalMem, totalPSS, info.lastTrimLevel, largeMemoryClreplaced, nativePSS, dalvikPSS, otherPSS, threshold, lowMemory));
return outputData;
}
17
Source : WXUtils.java
with Apache License 2.0
from weexext
with Apache License 2.0
from weexext
public static long getAvailMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// mi.availMem; 当前系统的可用内存
// return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
WXLogUtils.w("app AvailMemory ---->>>" + mi.availMem / (1024 * 1024));
return mi.availMem / (1024 * 1024);
}
17
Source : DeviceInfo.java
with Apache License 2.0
from webianks
with Apache License 2.0
from webianks
private static long getFreeMemory(Context activity) {
try {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
// in megabyte (mb)
long availableMegs = mi.availMem / 1048576L;
return availableMegs;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
17
Source : DeviceInfo.java
with Apache License 2.0
from webianks
with Apache License 2.0
from webianks
@SuppressLint("NewApi")
private static long getTotalMemory(Context activity) {
try {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
// in megabyte (mb)
long availableMegs = mi.totalMem / 1048576L;
return availableMegs;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
17
Source : Device.java
with Mozilla Public License 2.0
from tzz2015
with Mozilla Public License 2.0
from tzz2015
public long getAvailMem() {
ActivityManager activityManager = getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(info);
return info.availMem;
}
17
Source : Device.java
with Mozilla Public License 2.0
from tzz2015
with Mozilla Public License 2.0
from tzz2015
public long getTotalMem() {
ActivityManager activityManager = getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(info);
return info.totalMem;
}
17
Source : DeviceUtils.java
with Apache License 2.0
from smuyyh
with Apache License 2.0
from smuyyh
/**
* 获取系统当前可用内存大小
*
* @param context
* @return
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getAvailMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// 将获取的内存大小规格化
return Formatter.formatFileSize(context, mi.availMem);
}
17
Source : ProcessManager.java
with Apache License 2.0
from RuijiePan
with Apache License 2.0
from RuijiePan
public long killAllRunningApp() {
long beforeMemory = 0;
long endMemory = 0;
mActivityManager.getMemoryInfo(mMemoryInfo);
beforeMemory = mMemoryInfo.availMem;
for (AppProcessInfo info : getRunningProcessList()) {
killBackgroundProcesses(info.getProcessName());
}
mActivityManager.getMemoryInfo(mMemoryInfo);
endMemory = mMemoryInfo.availMem;
return endMemory - beforeMemory;
}
17
Source : ProcessFragment.java
with GNU General Public License v3.0
from PowerExplorer
with GNU General Public License v3.0
from PowerExplorer
void updateStatus() {
final MemoryInfo mem_info = new ActivityManager.MemoryInfo();
final ActivityManager systemService = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
systemService.getMemoryInfo(mem_info);
rightStatus.setText(String.format("Available memory: %s B", Util.nf.format((mem_info.availMem)) + "/" + Util.nf.format(mem_info.totalMem)));
// numProc_label.setText("Number of processes: " + display_process.size());
selectionStatusTV.setText(selectedInList1.size() + "/" + lpinfo.size() + "/" + display_process.size());
adapter.notifyDataSetChanged();
}
17
Source : Util.java
with GNU General Public License v3.0
from mollyim
with GNU General Public License v3.0
from mollyim
public static long getAvailMemory(@NonNull Context context) {
ActivityManager activityManager = ServiceUtil.getActivityManager(context);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
return memoryInfo.availMem - memoryInfo.threshold;
}
17
Source : Utils.java
with GNU General Public License v3.0
from LookCos
with GNU General Public License v3.0
from LookCos
// 获取总内存大小
public static String getTotalRAM() {
long size = 0;
Context context = MainActivity.getContext();
ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(outInfo);
size = outInfo.totalMem;
return Formatter.formatFileSize(context, size);
}
17
Source : Utils.java
with GNU General Public License v3.0
from LookCos
with GNU General Public License v3.0
from LookCos
// 获取可用内存大小
public static String getAvailableRAM() {
Context context = MainActivity.getContext();
long size = 0;
ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(outInfo);
size = outInfo.availMem;
return Formatter.formatFileSize(context, size);
}
17
Source : DeviceInfoUtil.java
with MIT License
from liuguangli
with MIT License
from liuguangli
public static long getFreeMemory(Context context) {
// 获取android当前可用内存大小
long fm = 0;
try {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
fm = mi.availMem / (1024 * 1024);
} catch (Exception e) {
}
return fm;
}
17
Source : MemoryUtil.java
with Apache License 2.0
from Kyson
with Apache License 2.0
from Kyson
/**
* 同步获取系统的总ram大小
*
* @param activityManager
* @return
*/
private static long getRamTotalMem(ActivityManager activityManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(mi);
return mi.totalMem / 1024;
} else if (sTotalMem.get() > 0L) {
// 如果已经从文件获取过值,则不需要再次获取
return sTotalMem.get();
} else {
final long tm = getRamTotalMemByFile();
sTotalMem.set(tm);
return tm;
}
}
17
Source : MyRenderer.java
with GNU General Public License v3.0
from jsmith613
with GNU General Public License v3.0
from jsmith613
private void doFps() {
_frameCount++;
long now = System.currentTimeMillis();
long delta = now - _timeLastSample;
if (delta >= FRAMERATE_SAMPLEINTERVAL_MS) {
_fps = _frameCount / (delta / 1000f);
_activityManager.getMemoryInfo(_memoryInfo);
Log.v(Min3d.TAG, "FPS: " + Math.round(_fps) + ", availMem: " + Math.round(_memoryInfo.availMem / 1048576) + "MB");
_timeLastSample = now;
_frameCount = 0;
}
}
17
Source : BitmapUtils.java
with Apache License 2.0
from jruesga
with Apache License 2.0
from jruesga
public static int calculateMaxAvailableSize(Context context) {
if (AndroidHelper.isJellyBeanOrGreater()) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
return (int) ((mi.totalMem / 1073741824) * 1024);
}
// The minimum for all android devices
return 1024;
}
17
Source : MemoryUtil.java
with MIT License
from jeasinlee
with MIT License
from jeasinlee
/**
* Get available memory
*
* @param context
* @return
*/
public static String getAvailableMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return Formatter.formatFileSize(context, mi.availMem);
}
17
Source : MemInfo.java
with MIT License
from januslo
with MIT License
from januslo
// 获得可用的内存
public static long getmem_UNUSED(Context mContext) {
long MEM_UNUSED;
// 得到ActivityManager
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
// 创建ActivityManager.MemoryInfo对象
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// 取得剩余的内存空间
MEM_UNUSED = mi.availMem / 1048576;
return MEM_UNUSED;
}
17
Source : SystemUtils.java
with MIT License
from hubcarl
with MIT License
from hubcarl
private String[] getTotalMemory() {
// 1-total 2-avail
String[] result = { "", "" };
final ActivityManager activityManager = (ActivityManager) AppMain.getInstance().getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(mi);
long mTotalMem = 0;
long mAvailMem = mi.availMem;
String str1 = "/proc/meminfo";
String str2;
String[] arrayOfString;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
str2 = localBufferedReader.readLine();
arrayOfString = str2.split("\\s+");
mTotalMem = Integer.valueOf(arrayOfString[1]).intValue() * 1024;
localBufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
result[0] = Formatter.formatFileSize(AppMain.getInstance(), mTotalMem);
result[1] = Formatter.formatFileSize(AppMain.getInstance(), mAvailMem);
Log.i(">>>SystemUtils", "meminfo total:" + result[0] + " used:" + result[1]);
return result;
}
17
Source : MemoryInfo.java
with Apache License 2.0
from guxiaonian
with Apache License 2.0
from guxiaonian
/**
* 获取android当前可用内存大小
*
* @param context
* @return
*/
private static String getAvailMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
if (am != null) {
am.getMemoryInfo(mi);
}
// mi.availMem; 当前系统的可用内存
return Formatter.formatFileSize(context, mi.availMem);
}
17
Source : HardwareCollector.java
with MIT License
from ForgeRock
with MIT License
from ForgeRock
private Long getRam(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager != null) {
activityManager.getMemoryInfo(mi);
return mi.totalMem / 1048576L;
}
return null;
}
17
Source : DeviceUtils.java
with Apache License 2.0
from didi
with Apache License 2.0
from didi
/**
* @param context
* @return 手机当前可用内存(兆)
*/
public static long getAvailMemory(Context context) {
// 获取android当前可用内存大小
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return mi.availMem / 1024 / 1024;
}
17
Source : StorageUtil.java
with Apache License 2.0
from coderJohnZhang
with Apache License 2.0
from coderJohnZhang
// 获得可用的内存
public long getmem_UNUSED(Context mContext) {
long MEM_UNUSED;
// 得到ActivityManager
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
// 创建ActivityManager.MemoryInfo对象
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// 取得剩余的内存空间
MEM_UNUSED = mi.availMem;
return MEM_UNUSED;
}
17
Source : AndroidUtil.java
with MIT License
from alibaba
with MIT License
from alibaba
/**
* 获取所有的内存大小(in k)
*
* @param context
* @return
*/
@TargetApi(16)
public static Long getTotalMemorySize(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return mi != null ? mi.totalMem : null;
} else {
return null;
}
}
17
Source : AndroidUtil.java
with MIT License
from alibaba
with MIT License
from alibaba
/**
* 获取可用的内存大小(in k)
*
* @param context
* @return
*/
public static Long getAvailMemorySize(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
return mi != null ? mi.availMem : null;
}
17
Source : DeviceUtil.java
with GNU General Public License v3.0
from AdTiming
with GNU General Public License v3.0
from AdTiming
public static long getTotalRAM(Context context) {
if (context == null) {
return 0;
}
long size;
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(outInfo);
size = outInfo.totalMem;
return size;
}
16
Source : SystemTool.java
with GNU General Public License v3.0
from z-chu
with GNU General Public License v3.0
from z-chu
/**
* 获取设备的可用内存大小
*
* @param cxt 应用上下文对象context
* @return 当前内存大小
*/
public static int getDeviceUsableMemory(Context cxt) {
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo mi = new MemoryInfo();
am.getMemoryInfo(mi);
// 返回当前系统的可用内存
return (int) (mi.availMem / (1024 * 1024));
}
16
Source : MemoryUtil.java
with Apache License 2.0
from wzx54321
with Apache License 2.0
from wzx54321
/**
* Get available memory info.
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getAvailMemory(Context context) {
// 获取android当前可用内存大小
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// mi.availMem; 当前系统的可用内存
// 将获取的内存大小规格化
return Formatter.formatFileSize(context, mi.availMem);
}
16
Source : MemoryUtil.java
with Apache License 2.0
from wzx54321
with Apache License 2.0
from wzx54321
/**
* Get memory info of device.
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static ActivityManager.MemoryInfo getMemoryInfo(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return mi;
}
16
Source : SystemUtil.java
with Apache License 2.0
from TanZhiL
with Apache License 2.0
from TanZhiL
public static long getAvailMemoryL(Context mContext) {
// 获取android当前可用内存大小
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// 将获取的内存大小规格化
return mi.availMem;
}
16
Source : SystemUtil.java
with Apache License 2.0
from TanZhiL
with Apache License 2.0
from TanZhiL
public static long getTotalMemoryL(Context mContext) {
// 获取android当前可用内存大小
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// 将获取的内存大小规格化
return mi.totalMem;
}
See More Examples