android 內存等使用情況

package com.gallery;

import android.app.Activity;
import android.app.ActivityManager;
import android.os.Bundle;
import android.widget.TextView;

public class SystemProperty extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
	}

	/** * 显示数据存库 */
	private StringBuffer buffer;

	@Override
	protected void onStart() {
		super.onStart();
		initProperty();
		getMemoryInfo();
		TextView tv = new TextView(this);
		tv.setText(buffer.toString());
		this.setContentView(tv);
	}

	/** * 系统信息查看方法 */
	private void initProperty() {
		initProperty("java.vendor.url", "java.vendor.url");
		initProperty("java.class.path", "java.class.path");
		initProperty("user.home", "user.home");
		initProperty("java.class.version", "java.class.version");
		initProperty("os.version", "os.version");
		initProperty("java.vendor", "java.vendor");
		initProperty("user.dir", "user.dir");
		initProperty("user.timezone", "user.timezone");
		initProperty("path.separator", "path.separator");
		initProperty(" os.name", " os.name");
		initProperty("os.arch", "os.arch");
		initProperty("line.separator", "line.separator");
		initProperty("file.separator", "file.separator");
		initProperty("user.name", "user.name");
		initProperty("java.version", "java.version");
		initProperty("java.home", "java.home");
	}

	private void initProperty(String description, String propertyStr) {
		if (buffer == null) {
			buffer = new StringBuffer();
		}
		buffer.append(description).append("--->:");
		buffer.append(System.getProperty(propertyStr)).append("\n");
		 getMemoryInfo();
	}

	/** * 系统内存情况查看 */
	private void getMemoryInfo() {
		final ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
		ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
		activityManager.getMemoryInfo(outInfo);
		buffer.append("\n剩余内存:---->").append(outInfo.availMem >> 10)
				.append("k");
		buffer.append("\n剩余内存:---->").append(outInfo.availMem >> 20)
				.append("M");
		buffer.append("\n是否处于低内存状态:----->").append(outInfo.lowMemory);
	}
}

 

你可能感兴趣的:(java,android,OS)