Search in sources :

Example 1 with MemoryInfo

use of android.app.ActivityManager.MemoryInfo in project superCleanMaster by joyoyao.

the class AppUtil method getAvailMemory.

/**
     *
     * 描述:解析数据.
     *
     * @param info
     *            User 39%, System 17%, IOW 3%, IRQ 0%
     * @return
     */
// public static AbCPUInfo parseCPUInfo(String info) {
// AbCPUInfo CPUInfo = new AbCPUInfo();
// String tempString = "";
// String[] rows = null;
// String[] columns = null;
// rows = info.split("[\n]+");
// // 使用正则表达式分割字符串
// for (int i = 0; i < rows.length; i++) {
// tempString = rows[i];
// //AbLogUtil.d(AbAppUtil.class, tempString);
// if (tempString.indexOf("User") != -1 && tempString.indexOf("System") !=
// -1) {
// tempString = tempString.trim();
// columns = tempString.split(",");
// for(int j = 0; j < columns.length; j++){
// String col = columns[j].trim();
// String[] cpu = col.split(" ");
// if(j == 0){
// CPUInfo.User = cpu[1];
// }else if(j == 1){
// CPUInfo.System = cpu[1];
// }else if(j == 2){
// CPUInfo.IOW = cpu[1];
// }else if(j == 3){
// CPUInfo.IRQ = cpu[1];
// }
// }
// }
// }
// return CPUInfo;
// }
/**
     * 描述:获取可用内存.
     *
     * @param context
     * @return
     */
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;
}
Also used : MemoryInfo(android.app.ActivityManager.MemoryInfo) ActivityManager(android.app.ActivityManager)

Example 2 with MemoryInfo

use of android.app.ActivityManager.MemoryInfo in project packer-ng-plugin by mcxiaoke.

the class MainActivity method addDeviceInfoSection.

@SuppressLint("NewApi")
private void addDeviceInfoSection() {
    StringBuilder builder = new StringBuilder();
    builder.append("[Device]\n");
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    final MemoryInfo memoryInfo = new MemoryInfo();
    am.getMemoryInfo(memoryInfo);
    if (AndroidUtils.hasJellyBean()) {
        builder.append("Mem Total: ").append(StringUtils.getHumanReadableByteCount(memoryInfo.totalMem)).append("\n");
    }
    builder.append("Mem Free: ").append(StringUtils.getHumanReadableByteCount(memoryInfo.availMem)).append("\n");
    builder.append("Mem Heap: ").append(am.getMemoryClass()).append("M\n");
    builder.append("Mem Low: ").append(memoryInfo.lowMemory).append("\n");
    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics dm = new DisplayMetrics();
    //DisplayMetrics dm = getResources().getDisplayMetrics();
    display.getMetrics(dm);
    int statusBarHeightDp = ViewUtils.getStatusBarHeightInDp(this);
    int systemBarHeightDp = ViewUtils.getSystemBarHeightInDp(this);
    int statusBarHeight = ViewUtils.getStatusBarHeight(this);
    int systemBarHeight = ViewUtils.getSystemBarHeight(this);
    Point point = getScreenRawSize(display);
    builder.append("statusBarHeightDp: ").append(statusBarHeightDp).append("\n");
    builder.append("systemBarHeightDp: ").append(systemBarHeightDp).append("\n");
    builder.append("statusBarHeightPx: ").append(statusBarHeight).append("\n");
    builder.append("systemBarHeightPx: ").append(systemBarHeight).append("\n");
    builder.append("screenWidth: ").append(point.x).append("\n");
    builder.append("screenHeight: ").append(point.y).append("\n");
    builder.append("WindowWidth: ").append(dm.widthPixels).append("\n");
    builder.append("WindowHeight: ").append(dm.heightPixels).append("\n");
    builder.append(toString2(dm));
    builder.append("\n");
    addSection(builder.toString());
}
Also used : MemoryInfo(android.app.ActivityManager.MemoryInfo) Point(android.graphics.Point) ActivityManager(android.app.ActivityManager) DisplayMetrics(android.util.DisplayMetrics) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Display(android.view.Display) SuppressLint(android.annotation.SuppressLint)

Example 3 with MemoryInfo

use of android.app.ActivityManager.MemoryInfo in project cube-sdk by liaohuqiu.

the class SystemWatcher method run.

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);
}
Also used : MemoryInfo(android.app.ActivityManager.MemoryInfo) TimerTask(java.util.TimerTask) Timer(java.util.Timer) ActivityManager(android.app.ActivityManager)

Example 4 with MemoryInfo

use of android.app.ActivityManager.MemoryInfo in project Lazy by l123456789jy.

the class AppUtils method getDeviceUsableMemory.

/**
     * 获取设备的可用内存大小
     *
     * @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));
}
Also used : MemoryInfo(android.app.ActivityManager.MemoryInfo) ActivityManager(android.app.ActivityManager)

Example 5 with MemoryInfo

use of android.app.ActivityManager.MemoryInfo in project KJFrameForAndroid by kymjs.

the class SystemTool method getDeviceUsableMemory.

/**
     * 获取设备的可用内存大小
     * 
     * @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));
}
Also used : MemoryInfo(android.app.ActivityManager.MemoryInfo) ActivityManager(android.app.ActivityManager)

Aggregations

MemoryInfo (android.app.ActivityManager.MemoryInfo)26 ActivityManager (android.app.ActivityManager)12 Point (android.graphics.Point)2 SuppressLint (android.annotation.SuppressLint)1 DisplayMetrics (android.util.DisplayMetrics)1 Display (android.view.Display)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1