DBMNG数据库管理与应用

书籍是全世界的营养品。生活里没有书籍,就好像没有阳光;智慧里没有书籍,就好像鸟儿没有翅膀。
当前位置:首页 > 移动应用 > Android

android获取手机信息

	/**
	 * 获取android当前可用内存大小 
	 */
	 private String getAvailMemory() {// 获取android当前可用内存大小   
		  
	        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);  
	        MemoryInfo mi = new MemoryInfo();  
	        am.getMemoryInfo(mi);  
	        //mi.availMem; 当前系统的可用内存   
	  
	        return Formatter.formatFileSize(getBaseContext(), mi.availMem);// 将获取的内存大小规格化   
	    }  

	/**
	 * 获得系统总内存
	 */
	private String getTotalMemory() {
		String str1 = "/proc/meminfo";// 系统内存信息文件 
		String str2;
		String[] arrayOfString;
		long initial_memory = 0;

		try {
		FileReader localFileReader = new FileReader(str1);
		BufferedReader localBufferedReader = new BufferedReader(
		localFileReader, 8192);
		str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小 

		arrayOfString = str2.split("\\s+");
		for (String num : arrayOfString) {
		Log.i(str2, num + "\t");
		}

		initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte 
		localBufferedReader.close();

		} catch (IOException e) {
		}
		return Formatter.formatFileSize(getBaseContext(), initial_memory);// Byte转换为KB或者MB,内存大小规格化 
		}

	/**
	 * 获得手机屏幕宽高
	 * @return
	 */
	public String getHeightAndWidth(){
		int width=getWindowManager().getDefaultDisplay().getWidth();
		int heigth=getWindowManager().getDefaultDisplay().getHeight();
		String str=width+""+heigth+"";
		return str;
	}
	/**
	 * 获取IMEI号,IESI号,手机型号
	 */
	private void getInfo() {
       TelephonyManager mTm = (TelephonyManager)this.getSystemService(TELEPHONY_SERVICE);
        String imei = mTm.getDeviceId();
        String imsi = mTm.getSubscriberId();
        String mtype = android.os.Build.MODEL; // 手机型号
        String mtyb= android.os.Build.BRAND;//手机品牌
        String numer = mTm.getLine1Number(); // 手机号码,有的可得,有的不可得
        Log.i("text", "手机IMEI号:"+imei+"手机IESI号:"+imsi+"手机型号:"+mtype+"手机品牌:"+mtyb+"手机号码"+numer);
    }
	/**
	 * .获取手机MAC地址
	 * 只有手机开启wifi才能获取到mac地址
	 */
	private String getMacAddress(){
        String result = "";
        WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        result = wifiInfo.getMacAddress();
        Log.i("text", "手机macAdd:" + result);
        return result;
    }
	/**
	 * 手机CPU信息
	 */
	private String[] getCpuInfo() {
        String str1 = "/proc/cpuinfo";
        String str2 = "";
        String[] cpuInfo = {"", ""};  //1-cpu型号  //2-cpu频率
        String[] arrayOfString;
        try {
            FileReader fr = new FileReader(str1);
            BufferedReader localBufferedReader = new BufferedReader(fr, 8192);
            str2 = localBufferedReader.readLine();
            arrayOfString = str2.split("\\s+");
            for (int i = 2; i < arrayOfString.length; i++) {
                cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " ";
            }
            str2 = localBufferedReader.readLine();
            arrayOfString = str2.split("\\s+");
            cpuInfo[1] += arrayOfString[2];
            localBufferedReader.close();
        } catch (IOException e) {
        }
        Log.i("text", "cpuinfo:" + cpuInfo[0] + " " + cpuInfo[1]);
        return cpuInfo;
    }
本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号