android---获取设备相关信息
2013-11-05 16:34
344 查看
public class DevManager { private static final String TAG = "CpuManager"; Context mContext; public DevManager() { } public DevManager(Context context) { mContext = context; } // 获取CPU最大频率(单位KHZ) // "/system/bin/cat" 命令行 // "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" 存储最大频率的文件的路径 public static String getMaxCpuFreq() { String result = ""; ProcessBuilder cmd; try { String[] args = { "/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" }; cmd = new ProcessBuilder(args); Process process = cmd.start(); InputStream in = process.getInputStream(); byte[] re = new byte[24]; while (in.read(re) != -1) { result = result + new String(re); } in.close(); } catch (IOException ex) { ex.printStackTrace(); result = "N/A"; } return result.trim(); } // 获取CPU最小频率(单位KHZ) public static String getMinCpuFreq() { String result = ""; ProcessBuilder cmd; try { String[] args = { "/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq" }; cmd = new ProcessBuilder(args); Process process = cmd.start(); InputStream in = process.getInputStream(); byte[] re = new byte[24]; while (in.read(re) != -1) { result = result + new String(re); } in.close(); } catch (IOException ex) { ex.printStackTrace(); result = "N/A"; } return result.trim(); } // 实时获取CPU当前频率(单位KHZ) public static String getCurCpuFreq() { String result = "N/A"; try { FileReader fr = new FileReader("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"); BufferedReader br = new BufferedReader(fr); String text = br.readLine(); result = text.trim(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; } // 获取CPU名字 public static String getCpuName() { try { FileReader fr = new FileReader("/proc/cpuinfo"); BufferedReader br = new BufferedReader(fr); String text = br.readLine(); String[] array = text.split(":\\s+", 2); for (int i = 0; i < array.length; i++) { } return array[1]; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } // 内存 public void getTotalMemory() { String str1 = "/proc/meminfo"; String str2 = ""; try { FileReader fr = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader(fr, 8192); while ((str2 = localBufferedReader.readLine()) != null) { Log.i(TAG, "---" + str2); } } catch (IOException e) { } } // rom大小 public long[] getRomMemroy() { long[] romInfo = new long[2]; // Total rom memory romInfo[0] = getTotalInternalMemorySize(); // Available rom memory File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); romInfo[1] = blockSize * availableBlocks; getVersion(); return romInfo; } public long getTotalInternalMemorySize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; } // sd卡大小 public long[] getSDCardMemory() { long[] sdCardInfo = new long[2]; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { File sdcardDir = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(sdcardDir.getPath()); long bSize = sf.getBlockSize(); long bCount = sf.getBlockCount(); long availBlocks = sf.getAvailableBlocks(); sdCardInfo[0] = bSize * bCount;// 总大小 sdCardInfo[1] = bSize * availBlocks;// 可用大小 } return sdCardInfo; } // 电池容量 private BroadcastReceiver batteryReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int level = intent.getIntExtra("level", 0); // level加%就是当前电量了 } }; // registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); // 系统版本信息 public String[] getVersion() { String[] version = { "null", "null", "null", "null" }; String str1 = "/proc/version"; String str2; String[] arrayOfString; try { FileReader localFileReader = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192); str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); version[0] = arrayOfString[2];// KernelVersion localBufferedReader.close(); } catch (IOException e) { } version[1] = Build.VERSION.RELEASE;// firmware version version[2] = Build.MODEL;// model version[3] = Build.DISPLAY;// system version return version; } // mac地址和开机时间 public String[] getOtherInfo() { String[] other = { "null", "null" }; WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo.getMacAddress() != null) { other[0] = wifiInfo.getMacAddress(); } else { other[0] = "Fail"; } other[1] = getTimes(); return other; } private String getTimes() { long ut = SystemClock.elapsedRealtime() / 1000; if (ut == 0) { ut = 1; } int m = (int) ((ut / 60) % 60); int h = (int) ((ut / 3600)); // return h + " " + mContext.getString(R.string.info_times_hour) + m + " " + mContext.getString(R.string.info_times_minute); return h + " " + "时" + m + " " + "分"; } }
相关文章推荐
- Android下使用TelephonyManager类获取设备电话相关信息
- Android开发中获取设备相关信息
- android 获取手机设备相关信息
- android系统获取系统相关信息(如Android设备的唯一ID等)原理
- android获取设备相关信息
- Android下使用TelephonyManager类获取设备电话相关信息
- [Android]获取设备相关信息
- android系统获取系统相关信息(如Android设备的唯一ID等)(源码)
- Android ADB工具-操作手机和获取手设备信息(四)
- Android常见的手机设备信息获取
- Android - 获取设备基础信息
- android获取连接到手机热点上的设备的信息
- Android 图片Exif信息相关的获取与修改
- Android获取包相关信息--code
- 【Android】获取手机的相关硬件信息
- android 安卓APP获取手机设备信息和手机号码的代码示例
- Android 获取设备各种信息以及其它
- 获取当前设备类型和相关信息
- Android 获取手机的IMEI等设备信息
- 获取android设备已安装应用信息