SoFunction
Updated on 2025-04-10

Android tool class for obtaining mobile phone information

Some codes collected online to obtain collection information are made into a tool class, which can be easily called in the future.

import ;
import ;
import ;

import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;

/**
  * Get mobile phone information tool category
  *
  */
public class PhoneUtil {

  private static PhoneUtil instance;

  private TelephonyManager tm;
  private Activity act;

  private PhoneUtil(Activity act) {
    tm = (TelephonyManager) (Context.TELEPHONY_SERVICE);
     = act;
  }

  public static PhoneUtil getInstance(Activity act) {
    if (instance == null) {
      instance = new PhoneUtil(act);
    } else if ( != act) {
      instance = new PhoneUtil(act);
    }
    return instance;
  }

  /** Is it in flight mode */
  public boolean isAirModeOpen() {
    return (((), .AIRPLANE_MODE_ON, 0) == 1 ? true
        : false);
  }

  /** Get mobile phone number */
  public String getPhoneNumber() {
    return tm == null ? null : tm.getLine1Number();
  }

  /** Get network type (not available for the time being) */
  public int getNetWorkType() {
    return tm == null ? 0 : ();
  }

  /** Get the serial number (IMSI) of the mobile phone sim card */
  public String getIMSI() {
    return tm == null ? null : ();
  }

  /** Get mobile phone IMEI */
  public String getIMEI() {
    return tm == null ? null : ();
  }

  /** Get mobile phone model */
  public static String getModel() {
    return ;
  }

  /** Get mobile phone brand */
  public static String getBrand() {
    return ;
  }

  /** Get mobile phone system version */
  public static String getVersion() {
    return ;
  }

  /** Obtain the total memory of the mobile phone system */
  public String getTotalMemory() {
    String str1 = "/proc/meminfo";// System memory information file    String str2;
    String[] arrayOfString;
    long initial_memory = 0;

    try {
      FileReader localFileReader = new FileReader(str1);
      BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
      str2 = ();// Read the first line of meminfo, the total memory size of the system
      arrayOfString = ("\\s+");

      initial_memory = (arrayOfString[1]).intValue() * 1024;// Get the total system memory, unit is KB, multiplied by 1024 to convert to Byte      ();

    } catch (IOException e) {
    }
    return (act, initial_memory);// Convert Byte to KB or MB, and the memory size is normalized  }

  /** Get the screen width of the phone */
  public int getScreenWidth() {
    return ().getDefaultDisplay().getWidth();
  }

  /** Get the height and width of the mobile phone screen */
  public int getScreenHeight() {
    return ().getDefaultDisplay().getHeight();
  }

  /** Get the application package name */
  public String getPackageName() {
    return ();
  }

  /**
    * Get the MAC address of the mobile phone. Only when the mobile phone is turned on wifi can you get the mac address
    */
  public String getMacAddress() {
    String result = "";
    WifiManager wifiManager = (WifiManager) (Context.WIFI_SERVICE);
    WifiInfo wifiInfo = ();
    result = ();
    return result;
  }

  /**
    * Get mobile phone CPU information //1-cpu model //2-cpu frequency
    */
  public String[] getCpuInfo() {
    String str1 = "/proc/cpuinfo";
    String str2 = "";
    String[] cpuInfo = { "", "" }; // 1-cpu model // 2-cpu frequency    String[] arrayOfString;
    try {
      FileReader fr = new FileReader(str1);
      BufferedReader localBufferedReader = new BufferedReader(fr, 8192);
      str2 = ();
      arrayOfString = ("\\s+");
      for (int i = 2; i < ; i++) {
        cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " ";
      }
      str2 = ();
      arrayOfString = ("\\s+");
      cpuInfo[1] += arrayOfString[2];
      ();
    } catch (IOException e) {
    }
    return cpuInfo;
  }

  /** Get meta-data content in Application */
  public String getMetaData(String name) {
    String result = "";
    try {
      ApplicationInfo appInfo = ().getApplicationInfo(getPackageName(),
          PackageManager.GET_META_DATA);
      result = (name);
    } catch (Exception e) {
      ();
    }
    return result;
  }

}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.