9久久伊人精品综合,亚洲一区精品视频在线,成 人免费va视频,国产一区二区三区黄网,99国产精品永久免费视频,亚洲毛片多多影院,精品久久久无码人妻中文字幕,无码国产欧美一区二区三区不卡
學習啦 > 學習電腦 > 電腦硬件知識 > 硬件知識 > 怎么通過代碼獲取手機的相關硬件信息

怎么通過代碼獲取手機的相關硬件信息

時間: 文輝886 分享

怎么通過代碼獲取手機的相關硬件信息

  想知道怎么用代碼來獲取手機的相關硬件信息嗎?別著急,今天就讓學習啦小編來教下大家吧,快來看看吧,希望能讓大家有所收獲!

  獲取手機相關硬件信息的代碼

  package com.liu.chad.practicesqlite;

  import android.app.ActivityManager;

  import android.content.Context;

  import android.os.Bundle;

  import android.support.v7.app.ActionBarActivity;

  import android.telephony.TelephonyManager;

  import android.text.format.Formatter;

  import android.util.Log;

  import android.widget.TextView;

  import java.io.BufferedReader;

  import java.io.FileNotFoundException;

  import java.io.FileReader;

  import java.io.IOException;

  import java.io.InputStream;

  public class MainActivity extends ActionBarActivity {

  private TextView mTextView;

  @Override

  protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

  mTextView = (TextView) findViewById(R.id.textViewId);

  getPhoneInfo();

  }

  /**

  * 獲取手機信息

  */

  public void getPhoneInfo() {

  TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);

  String mtyb = android.os.Build.BRAND;// 手機品牌

  String mtype = android.os.Build.MODEL; // 手機型號

  String imei = tm.getDeviceId();

  String imsi = tm.getSubscriberId();

  String numer = tm.getLine1Number(); // 手機號碼

  String serviceName = tm.getSimOperatorName(); // 運營商

  mTextView.setText("品牌: " + mtyb + "\n" + "型號: " + mtype + "\n" + "版本: Android "

  + android.os.Build.VERSION.RELEASE + "\n" + "IMEI: " + imei

  + "\n" + "IMSI: " + imsi + "\n" + "手機號碼: " + numer + "\n"

  + "運營商: " + serviceName + "\n");

  mTextView.append("總內存: " + getTotalMemory() + "\n");

  mTextView.append("當前可用內存: " + getAvailMemory() + "\n");

  mTextView.append("CPU名字: " + getCpuName() + "\n");

  mTextView.append("CPU最大頻率: " + getMaxCpuFreq() + "\n");

  mTextView.append("CPU最小頻率: " + getMinCpuFreq() + "\n");

  mTextView.append("CPU當前頻率: " + getCurCpuFreq() + "\n");

  }

  /**

  * 獲取手機內存大小

  *

  * @return

  */

  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

  */

  private String getAvailMemory() {

  ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

  ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();

  am.getMemoryInfo(mi);

  return Formatter.formatFileSize(getBaseContext(), mi.availMem);

  }

  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() + "Hz";

  }

  // 獲取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() + "Hz";

  }

  // 實時獲取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() + "Hz";

  } catch (FileNotFoundException e) {

  e.printStackTrace();

  } catch (IOException e) {

  e.printStackTrace();

  }

  return result;

  }

  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;

  }

  }

1689078 主站蜘蛛池模板: 日韩精品成人网页视频在线| 中文字幕日韩精品人妻| 欧美熟妇xxxxx欧美老妇不卡 | 91毛片网| 99欧美日本一区二区留学生| 国产日韩入口一区二区| 午夜福利宅福利国产精品| 日韩中文字幕免费在线观看| 中文字幕精品亚洲无线码二区| 亚洲一区二区三区在线观看精品中文| 熟女国产精品一区二区三| 精品一区二区三区在线观看l| 开心一区二区三区激情| 国产熟女精品一区二区三区 | 香蕉久久国产精品免| 毛片内射久久久一区| 国产线播放免费人成视频播放| 亚洲av免费成人精品区| 欧美黑人巨大videos精品| 免费视频欧美无人区码 | 亚洲av一区二区在线看| 激情综合五月| 亚洲精品久综合蜜| 欧美精品一区二区三区中文字幕| V一区无码内射国产| 国产精品中文字幕久久| 18禁在线一区二区三区| 亚洲国产一区二区av| 中文字幕有码无码AV| 一个色的导航| 国内精品久久久久影视| 五月综合婷婷开心综合婷婷| 另类 专区 欧美 制服| 熟妇人妻无码中文字幕老熟妇| 亚洲欧洲一区二区福利片| 亚洲国产精品色一区二区| 亚洲一区成人在线视频| 色视频不卡一区二区三区| 久久88香港三级台湾三级播放| 日韩在线视频网| 又粗又硬又黄a级毛片|