android获取手机信息大全

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

IMEI号,IESI号,手机型号:

[java]  view plain copy print ?
  1. private void getInfo() {    
  2.              TelephonyManager mTm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);    
  3.              String imei = mTm.getdeviceid();    
  4.              String imsi = mTm.getSubscriberId();    
  5.              String mtype = android.os.Build.MODEL; // 手机型号    
  6.              String numer = mTm.getLine1Number(); // 手机号码,有的可得,有的不可得    
  7.          }  
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView textView = (TextView) findViewById(R.id.text);
    textView.setText("Product Model: " + android.os.Build.MODEL + ","
                + android.os.Build.VERSION.SDK + ","
                + android.os.Build.VERSION.RELEASE);
}

String MODEL The end-user-visible name for the end product.
String SDK This constant is deprecated. Use SDK_INT to easily get this as an integer.
String RELEASE The user-visible version string.

String BOARD The name of the underlying board,like "goldfish".
String BOOTLOADER The system bootloader version number.
String BRAND The brand (e.g.,carrier) the software is customized for,if any.
String CPU_ABI The name of the instruction set (cpu type + ABI convention) of native code.
String CPU_ABI2 The name of the second instruction set (cpu type + ABI convention) of native code.
String DEVICE The name of the industrial design.
String DISPLAY A build ID string meant for displaying to the user
String FINGERPRINT A string that uniquely identifies this build.
String HARDWARE The name of the hardware (from the kernel command line or /proc).
String HOST  
String ID Either a changelist number,or a label like "M4-rc20".
String MANUFACTURER The manufacturer of the product/hardware.
String MODEL The end-user-visible name for the end product.
String PRODUCT The name of the overall product.
String RADIO The radio firmware version number.
String SERIAL A hardware serial number,if available.
String TAGS Comma-separated tags describing the build,like "unsigned,debug".
long TIME  
String TYPE The type of build,like "user" or "eng".
String UNKNOWN Value used for when a build property is unkNown.
String USER


获取手机屏幕高度:

[java]  view plain copy print ?
  1. private void getWeithAndHeight(){    
  2.             //这种方式在service中无法使用,    
  3.             displayMetrics dm = new displayMetrics();    
  4.             getwindowManager().getDefaultdisplay().getMetrics(dm);    
  5.             String width = dm.widthPixels;              //宽    
  6.             String height = dm.heightPixels;           //高    
  7.          
  8.             //在service中也能得到高和宽    
  9.             WindowManager mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);    
  10.             width = mWindowManager.getDefaultdisplay().getWidth();    
  11.             height = mWindowManager.getDefaultdisplay().getHeight();    
  12.         }  


获取手机MAC地址:

[java]  view plain copy print ?
  1. private String getMacAddress(){    
  2.              String result = "";    
  3.              WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);    
  4.              WifiInfo wifiInfo = wifiManager.getConnectionInfo();    
  5.              result = wifiInfo.getMacAddress();    
  6.              Log.i(TAG, "macAdd:" + result);    
  7.              return result;    
  8.      }  

手机cpu信息

[java]  view plain copy print ?
  1. private String[] getcpuInfo() {    
  2.              String str1 = "/proc/cpuinfo";    
  3.              String str2 = "";    
  4.              String[] cpuInfo = {"", ""};  //1-cpu型号  //2-cpu频率    
  5.              String[] arrayofstring;    
  6.              try {    
  7.                  FileReader fr = new FileReader(str1);    
  8.                  BufferedReader localBufferedReader = new BufferedReader(fr, 8192);    
  9.                  str2 = localBufferedReader.readLine();    
  10.                  arrayofstring = str2.split("\\s+");    
  11.                  for (int i = 2; i < arrayofstring.length; i++) {    
  12.                      cpuInfo[] = cpuInfo[] + arrayofstring[i] + " ";    
  13.                  }    
  14.                  str2 = localBufferedReader.readLine();    
  15.                  arrayofstring = str2.split("\\s+");    
  16.                  cpuInfo[1] += arrayofstring[2];    
  17.                  localBufferedReader.close();    
  18.              } catch (IOException e) {    
  19.              }    
  20.              Log.i(TAG, "cpuinfo:" + cpuInfo[] + " " + cpuInfo[1]);    
  21.              return cpuInfo;    
  22.          }  

获取手机可用内存和总内存:

[java]  view plain copy print ?
  1. private String[] getTotalMemory() {    
  2.             String[] result = {"",""};  //1-total 2-avail    
  3.             ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();      
  4.             mActivityManager.getMemoryInfo(mi);      
  5.             long mTotalMem = ;    
  6.             long mAvailMem = mi.availMem;    
  7.             String str1 = "/proc/meminfo";    
  8.             String str2;    
  9.             String[] arrayofstring;    
  10.             try {    
  11.                 FileReader localFileReader = new FileReader(str1);    
  12.                 BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);    
  13.                 str2 = localBufferedReader.readLine();    
  14.                 arrayofstring = str2.split("\\s+");    
  15.                 mTotalMem = Integer.valueOf(arrayofstring[1]).intValue() * 1024;    
  16.                 localBufferedReader.close();    
  17.             } catch (IOException e) {    
  18.                 e.printstacktrace();    
  19.             }    
  20.             result[] = Formatter.formatFileSize(this, mTotalMem);    
  21.             result[1] = Formatter.formatFileSize(this, mAvailMem);    
  22.             Log.i(TAG, "meminfo total:" + result[] + " used:" + result[1]);    
  23.             return result;    
  24.         }  

获取手机安装的应用信息(排除系统自带):

[java]  view plain copy print ?
  1. private String getAllApp() {    
  2.              String result = "";    
  3.              List<PackageInfo> packages = getPackageManager().getInstalledPackages();    
  4.              for (PackageInfo i : packages) {    
  5.                  if ((i.applicationInfo.flags & ApplicationInfo.FLAG_SYstem) == ) {    
  6.                      result += i.applicationInfo.loadLabel(getPackageManager()).toString() + ",";    
  7.                  }    
  8.              }    
  9.              return result.substring(, result.length() - 1);    
  10.      }  

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

Java中的String是不可变对象 在面向对象及函数编程语言中,不...
String, StringBuffer 和 StringBuilder 可变性 String不可变...
序列化:把对象转换为字节序列的过程称为对象的序列化. 反序...
先说结论,是对象!可以继续往下看 数组是不是对象 什么是对...
为什么浮点数 float 或 double 运算的时候会有精度丢失的风险...
面试题引入 这里引申出一个经典问题,看下面代码 Integer a ...