android.app.ActivityManager.MemoryInfo Java Examples
The following examples show how to use
android.app.ActivityManager.MemoryInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemWatcher.java From cube-sdk with Apache License 2.0 | 6 votes |
public void run() { mTimerTask = new TimerTask() { @Override public void run() { MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Activity.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); Runtime runtime = Runtime.getRuntime(); String s = String.format("free:%s%% %sKB total:%sKB max:%sKB ", runtime.freeMemory() * 100f / runtime.totalMemory(), runtime.freeMemory(), runtime.totalMemory() / 1024, runtime.maxMemory() / 1024); // s += String.format("native: free:%sKB total:%sKB max:%sKB", android.os.Debug.getNativeHeapFreeSize() / 1024, android.os.Debug.getNativeHeapAllocatedSize() / 1024, // android.os.Debug.getNativeHeapSize() / 1024); // s += String.format("| availMem:%sKB", mi.availMem / 1024); Log.d("memory", s); } }; mTimer = new Timer(); mTimer.schedule(mTimerTask, 1000, 1000); }
Example #2
Source File: AppWatcher.java From Utils with Apache License 2.0 | 6 votes |
/** * watch for memory usage and heap size per seconds */ public void run() { mTimerTask = new TimerTask() { @Override public void run() { MemoryInfo memoryInfo = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Activity.ACTIVITY_SERVICE); activityManager.getMemoryInfo(memoryInfo); Runtime runtime = Runtime.getRuntime(); String msg = String.format("free:%s%% %sKB total:%sKB max:%sKB ", runtime.freeMemory() * 100f / runtime.totalMemory(), runtime.freeMemory(), runtime.totalMemory() / 1024, runtime.maxMemory() / 1024); msg += String.format("native: free:%sKB total:%sKB max:%sKB", android.os.Debug.getNativeHeapFreeSize() / 1024, android.os.Debug.getNativeHeapAllocatedSize() / 1024, android.os.Debug.getNativeHeapSize() / 1024); msg += String.format("| availMem:%sKB", memoryInfo.availMem / 1024); Log.d("memory", msg); } }; mTimer = new Timer(); mTimer.schedule(mTimerTask, 1000, 1000); }
Example #3
Source File: MemoryTools.java From SoloPi with Apache License 2.0 | 5 votes |
public static Long getAvailMemory(Context cx) {// 获取android当前可用内存大小 if (cx == null) { return 0L; } ActivityManager am = (ActivityManager) cx.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); LogUtil.i(TAG, "Available memory: " + mi.availMem); // mi.availMem; 当前系统的可用内存 return mi.availMem / BYTES_PER_MEGA;// 将获取的内存大小规格化 }
Example #4
Source File: TaskManager.java From Kernel-Tuner with GNU General Public License v3.0 | 5 votes |
public Integer getFreeRAM() { MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); return (int) (mi.availMem / 1048576L); }
Example #5
Source File: SystemInfoUtils.java From weixin with Apache License 2.0 | 5 votes |
/** * 获取可用的手机内存 * @param context 上下文 * @return */ public static long getAvailRAM(Context context){ ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo outInfo = new MemoryInfo(); am.getMemoryInfo(outInfo); return outInfo.availMem; }
Example #6
Source File: AndroidCompatibility.java From Cubes with MIT License | 5 votes |
protected AndroidCompatibility(AndroidLauncher androidLauncher) { super(androidLauncher, Application.ApplicationType.Android); this.androidLauncher = androidLauncher; modLoader = new AndroidModLoader(this); activityManager = (ActivityManager) androidLauncher.getSystemService(Activity.ACTIVITY_SERVICE); memoryInfo = new MemoryInfo(); }
Example #7
Source File: SystemTool.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
/** * 获取设备的可用内存大小 * * @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)); }
Example #8
Source File: EliminateMainActivity.java From android-tv-launcher with MIT License | 5 votes |
public long GetSurplusMemory() { info = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(info); long MemorySize = info.availMem; MemorySurPlus = (float) MemorySize / 1024 / 1024; return MemorySize; }
Example #9
Source File: SystemTool.java From Lay-s with MIT License | 5 votes |
/** * 获取设备的可用内存大小 * * @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)); }
Example #10
Source File: PhoneMemoryUtil.java From BalloonPerformer with Apache License 2.0 | 5 votes |
/** * 得到当前可用内存大小 * * @param context * @return */ public static long getAvailMemory(Context context) {// 获取android当前可用内存大小 ActivityManager am = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); return mi.availMem;// 将获取的内存大小规格化 }
Example #11
Source File: SystemUtils.java From VideoMeeting with Apache License 2.0 | 5 votes |
/** * 获取设备的可用内存大小 * * @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)); }
Example #12
Source File: AppUtils.java From MemoryCleaner with Apache License 2.0 | 5 votes |
/** * 描述:获取可用内存. */ public static long getAvailMemory(Context context) { // 获取android当前可用内存大小 ActivityManager activityManager = (ActivityManager) context.getSystemService( Context.ACTIVITY_SERVICE); MemoryInfo memoryInfo = new MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); // 当前系统可用内存 ,将获得的内存大小规格化 return memoryInfo.availMem; }
Example #13
Source File: SystemTool.java From Common with Apache License 2.0 | 5 votes |
/** * 获取设备的可用内存大小 * * @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)); }
Example #14
Source File: StorageUtils.java From FireFiles with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private long getSizeTotalRAM(boolean isTotal) { long sizeInBytes = 1000; MemoryInfo mi = new MemoryInfo(); activityManager.getMemoryInfo(mi); if(isTotal) { try { if(Utils.hasJellyBean()){ long totalMegs = mi.totalMem; sizeInBytes = totalMegs; } else{ RandomAccessFile reader = new RandomAccessFile("/proc/meminfo", "r"); String load = reader.readLine(); String[] totrm = load.split(" kB"); String[] trm = totrm[0].split(" "); sizeInBytes=Long.parseLong(trm[trm.length-1]); sizeInBytes=sizeInBytes*1024; reader.close(); } } catch (Exception e) { } } else{ long availableMegs = mi.availMem; sizeInBytes = availableMegs; } return sizeInBytes; }
Example #15
Source File: StorageUtils.java From FireFiles with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private long getSizeTotalRAM(boolean isTotal) { long sizeInBytes = 1000; MemoryInfo mi = new MemoryInfo(); activityManager.getMemoryInfo(mi); if(isTotal) { try { if(Utils.hasJellyBean()){ long totalMegs = mi.totalMem; sizeInBytes = totalMegs; } else{ RandomAccessFile reader = new RandomAccessFile("/proc/meminfo", "r"); String load = reader.readLine(); String[] totrm = load.split(" kB"); String[] trm = totrm[0].split(" "); sizeInBytes=Long.parseLong(trm[trm.length-1]); sizeInBytes=sizeInBytes*1024; reader.close(); } } catch (Exception e) { } } else{ long availableMegs = mi.availMem; sizeInBytes = availableMegs; } return sizeInBytes; }
Example #16
Source File: StorageUtils.java From FireFiles with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private long getSizeTotalRAM(boolean isTotal) { long sizeInBytes = 1000; MemoryInfo mi = new MemoryInfo(); activityManager.getMemoryInfo(mi); if(isTotal) { try { if(Utils.hasJellyBean()){ long totalMegs = mi.totalMem; sizeInBytes = totalMegs; } else{ RandomAccessFile reader = new RandomAccessFile("/proc/meminfo", "r"); String load = reader.readLine(); String[] totrm = load.split(" kB"); String[] trm = totrm[0].split(" "); sizeInBytes=Long.parseLong(trm[trm.length-1]); sizeInBytes=sizeInBytes*1024; reader.close(); } } catch (Exception e) { } } else{ long availableMegs = mi.availMem; sizeInBytes = availableMegs; } return sizeInBytes; }
Example #17
Source File: AppUtils.java From SmartChart with Apache License 2.0 | 5 votes |
/** * 获取设备的可用内存大小 * * @param context 应用上下文对象context * @return 当前内存大小 */ public static int getDeviceUsableMemory(Context context) { ActivityManager am = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); // 返回当前系统的可用内存 return (int) (mi.availMem / (1024 * 1024)); }
Example #18
Source File: SystemTool.java From FriendBook with GNU General Public License v3.0 | 5 votes |
/** * 获取设备的可用内存大小 * * @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)); }
Example #19
Source File: ProcessFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
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(); }
Example #20
Source File: MemoryTools.java From SoloPi with Apache License 2.0 | 5 votes |
/** * 获取总内存数据 * @return */ private Long getTotalMemory() { if (activityManager == null) { return 0L; } MemoryInfo info = new MemoryInfo(); activityManager.getMemoryInfo(info); return info.totalMem / BYTES_PER_MEGA; }
Example #21
Source File: MemoryTools.java From SoloPi with Apache License 2.0 | 5 votes |
public static Long getTotalMemory(Context cx) {// 获取android全部内存大小 if (cx == null) { return 0L; } ActivityManager am = (ActivityManager) cx.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); LogUtil.i(TAG, "Total memory: " + mi.totalMem); // mi.totalMem; 当前系统的全部内存 return mi.totalMem / BYTES_PER_MEGA;// 将获取的内存大小规格化 }
Example #22
Source File: SystemUtils.java From pandroid with Apache License 2.0 | 4 votes |
private static long getRamSizeAvailable(Context context) { long ramSize = 0; ActivityManager actManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo memInfo = new MemoryInfo(); actManager.getMemoryInfo(memInfo); ramSize = memInfo.availMem / (1024 * 1024); return ramSize; }
Example #23
Source File: Ram.java From KA27 with Apache License 2.0 | 4 votes |
public static int GetRam(boolean total, Context context) { MemoryInfo mMemoryInfo = new MemoryInfo(); ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mMemoryInfo); return (int)((total ? mMemoryInfo.totalMem : mMemoryInfo.availMem) >> 20); // log2(1024*1024) = 20 }
Example #24
Source File: StorageUtil.java From mobile-manager-tool with MIT License | 4 votes |
public static long getAvailMemory(Context context) { ActivityManager activityManager=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo memoryInfo = new MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); return memoryInfo.availMem / (1024 * 1024); }
Example #25
Source File: MedicAndroidJavascript.java From medic-android with GNU Affero General Public License v3.0 | 4 votes |
@org.xwalk.core.JavascriptInterface @android.webkit.JavascriptInterface public String getDeviceInfo() { try { if (activityManager == null) { return jsonError("ActivityManager not set. Cannot retrieve RAM info."); } if (connectivityManager == null) { return jsonError("ConnectivityManager not set. Cannot retrieve network info."); } String versionName = parent.getPackageManager() .getPackageInfo(parent.getPackageName(), 0) .versionName; JSONObject appObject = new JSONObject(); appObject.put("version", versionName); String androidVersion = Build.VERSION.RELEASE; int osApiLevel = Build.VERSION.SDK_INT; String osVersion = System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")"; JSONObject softwareObject = new JSONObject(); softwareObject .put("androidVersion", androidVersion) .put("osApiLevel", osApiLevel) .put("osVersion", osVersion); String device = Build.DEVICE; String model = Build.MODEL; String manufacturer = Build.BRAND; String hardware = Build.HARDWARE; Map<String, String> cpuInfo = getCPUInfo(); JSONObject hardwareObject = new JSONObject(); hardwareObject .put("device", device) .put("model", model) .put("manufacturer", manufacturer) .put("hardware", hardware) .put("cpuInfo", new JSONObject(cpuInfo)); File dataDirectory = Environment.getDataDirectory(); StatFs dataDirectoryStat = new StatFs(dataDirectory.getPath()); long dataDirectoryBlockSize = dataDirectoryStat.getBlockSizeLong(); long dataDirectoryAvailableBlocks = dataDirectoryStat.getAvailableBlocksLong(); long dataDirectoryTotalBlocks = dataDirectoryStat.getBlockCountLong(); long freeMemorySize = dataDirectoryAvailableBlocks * dataDirectoryBlockSize; long totalMemorySize = dataDirectoryTotalBlocks * dataDirectoryBlockSize; JSONObject storageObject = new JSONObject(); storageObject .put("free", freeMemorySize) .put("total", totalMemorySize); MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); long totalRAMSize = memoryInfo.totalMem; long freeRAMSize = memoryInfo.availMem; long thresholdRAM = memoryInfo.threshold; JSONObject ramObject = new JSONObject(); ramObject .put("free", freeRAMSize) .put("total", totalRAMSize) .put("threshold", thresholdRAM); NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo(); JSONObject networkObject = new JSONObject(); if (netInfo != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork()); int downSpeed = networkCapabilities.getLinkDownstreamBandwidthKbps(); int upSpeed = networkCapabilities.getLinkUpstreamBandwidthKbps(); networkObject .put("downSpeed", downSpeed) .put("upSpeed", upSpeed); } return new JSONObject() .put("app", appObject) .put("software", softwareObject) .put("hardware", hardwareObject) .put("storage", storageObject) .put("ram", ramObject) .put("network", networkObject) .toString(); } catch(Exception ex) { return jsonError("Problem fetching device info: ", ex); } }
Example #26
Source File: CommonUtils.java From letv with Apache License 2.0 | 4 votes |
public static long calculateFreeRamInBytes(Context context) { MemoryInfo mi = new MemoryInfo(); ((ActivityManager) context.getSystemService("activity")).getMemoryInfo(mi); return mi.availMem; }
Example #27
Source File: MemoryInfoUtil.java From letv with Apache License 2.0 | 4 votes |
public static long getMemUnused(Context context) { ActivityManager am = (ActivityManager) context.getSystemService("activity"); MemoryInfo memoryInfo = new MemoryInfo(); am.getMemoryInfo(memoryInfo); return memoryInfo.availMem / 1024; }
Example #28
Source File: AbAppUtil.java From FimiX8-RE with MIT License | 4 votes |
public static long getAvailMemory(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService("activity"); MemoryInfo memoryInfo = new MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); return memoryInfo.availMem; }
Example #29
Source File: CommonUtils.java From firebase-android-sdk with Apache License 2.0 | 2 votes |
/** * Calculates and returns the amount of free RAM in bytes. * * @param context used to acquire the necessary resources for calculating free RAM * @return Amount of free RAM in bytes */ public static long calculateFreeRamInBytes(Context context) { final MemoryInfo mi = new MemoryInfo(); ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mi); return mi.availMem; }