private static final String FILE_MEMORY = "/proc/meminfo";
private static final String FILE_CPU = "/proc/cpuinfo";
/**
* 得到IMEI
*
* @return
*/
public static final String getIMEI(Context context) {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId();
if (imei == null || imei.equals("000000000000000")) {
return "0";
}
return imei;
} /**
* 得到序列号
*
* @param context
* @return
*/
public static final String getSeriNumber(Context context) {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String sn = tm.getSimSerialNumber();
return sn;
} /**
* 得到IMSI
*
* @return
*/
public static final String getIMSI(Context context) {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String imsi = tm.getSimSerialNumber();
if (imsi == null || imsi.equals("000000000000000")) {
return "0";
}
return imsi;
}
/**
* <p>
* 手机可用内存大小
* </p>
*
* @param context
* @return
* @author chenfei
* @date 2013-1-4
*/
public static long getFreeMem(Context context) {
ActivityManager manager = (ActivityManager) context
.getSystemService(Activity.ACTIVITY_SERVICE);
MemoryInfo info = new MemoryInfo();
manager.getMemoryInfo(info);
long free = info.availMem / 1024 / 1024;
return free;
} /**
* <p>
* 手机整体内存大小
* </p>
*
* @param context
* @return
* @author chenfei
* @date 2013-1-4
*/
public static long getTotalMem(Context context) {
try {
FileReader fr = new FileReader(FILE_MEMORY);
BufferedReader br = new BufferedReader(fr);
String text = br.readLine();
String[] array = text.split("\\s+");
return Long.valueOf(array[1]) / 1024;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return -1;
} /**
* <p>
* 手机CPU型号
* </p>
*
* @return
* @author chenfei
* @date 2013-1-4
*/
public static String getCpuInfo() {
try {
FileReader fr = new FileReader(FILE_CPU);
BufferedReader br = new BufferedReader(fr);
String text = br.readLine();
String[] array = text.split(":\\s+", 2);
return array[1];
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
} /**
* <p>
* 手机型号 如 XT702
* </p>
*
* @return
* @author chenfei
* @date 2013-1-4
*/
public static String getModelName() {
return Build.MODEL;
} /**
* <p>
* 手机厂商名称
* </p>
*
* @return
* @author chenfei
* @date 2013-1-4
*/
public static String getManufacturerName() {
return Build.MANUFACTURER;
}
/**
* <p>
* 手机操作系统版本
* </p>
*
* @return
* @author chenfei
* @date 2013-1-4
*/
public static String getSoftSDKVersion() {
return Build.VERSION.RELEASE;// Firmware/OS 版本号
} /**
* 获取蓝牙mac地址
*
* @return
*/
public static String getBluetoothAddress() {
String address = BluetoothAdapter.getDefaultAdapter().getAddress();
return address == null ? "" : address;
} /**
* 获取上网方式
*
* @param mContext
* @return
*/
public static String getNetType(Context mContext) { String netType = "";
ConnectivityManager connectionManager = (ConnectivityManager) mContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectionManager.getActiveNetworkInfo();
if (null != info && info.isAvailable()) {
netType = info.getTypeName();
}
return netType;
} /**
* 判断网络连接是否可用
*
* @param mContext
* @return
*/ public static boolean getNetIsVali(Context mContext) { if (mContext != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) mContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager
.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
} /**
* 获取运营商信息
*
* @param mContext
* @return
*/
public static String getNetExtraInfo(Context mContext) { String netExtraInfo = "";
TelephonyManager mTm = (TelephonyManager) mContext
.getSystemService(Context.TELEPHONY_SERVICE);
if (mTm.getSimState() == TelephonyManager.SIM_STATE_READY) {
netExtraInfo = mTm.getSimOperator();
if (null != netExtraInfo) {
if (netExtraInfo.equals("46000")
|| netExtraInfo.equals("46002")
|| netExtraInfo.equals("46007")) {
// 中国移动
netExtraInfo = "中国移动";
} else if (netExtraInfo.equals("46001")) { // 中国联通
netExtraInfo = "中国联通";
} else if (netExtraInfo.equals("46003")) { // 中国电信
netExtraInfo = "中国电信";
} else {
netExtraInfo = "其他";
}
}
}
return netExtraInfo;
} /**
* 得到wifi地址
*
* @param context
* @return
*/
public static String getWIFIMac(Context context) {
WifiManager wifi = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String wifiMac = info.getMacAddress();
return wifiMac;
} /**
* 获取电话号码
*
* @param context
* @return
*/
public static String getPhoneNumber(Context context) {
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}

暂时先写这么多,部分机型获取获取不到一些属性比如电话号,蓝牙地址,序列号。使用时注意manifest中加入相应权限

android获取设备全部信息的更多相关文章

  1. [Android]获取设备相关信息

    public static int screenWidth(Activity activity) { DisplayMetrics dm = new DisplayMetrics(); activit ...

  2. linux驱动之获取设备树信息

    上一篇文章学习了字符设备的注册,操作过的小伙伴都知道上一篇文章中测试驱动时是通过手动创建设备节点的,现在开始学习怎么自动挂载设备节点和设备树信息的获取,这篇文章中的源码将会是我以后编写字符驱动的模板. ...

  3. Android 获取设备信息 异常

    /**获取设备信息 * @param c * @return */ public static void setDeviceInfo(Context c,RequestParams params){ ...

  4. 关于Android的Build类——获取Android手机设备各种信息

    经常遇到要获取Android手机设备的相关信息,来进行业务的开发,比如经常会遇到要获取CPU的类型来进行so库的动态的下载.而这些都是在Android的Build类里面.相关信息如下: private ...

  5. android获取设备唯一标示

    概述 有时需要对用户设备进行标识,所以希望能够得到一个稳定可靠并且唯一的识别码.虽然Android系统中提供了这样设备识别码,但是由于Android系统版本.厂商定制系统中的Bug等限制,稳定性和唯一 ...

  6. 【转】 android获取设备唯一标识完美解决方案

    <p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(51, 51, 51);  ...

  7. Android 获取设备唯一标识码

    概述 有时需要对用户设备进行标识,所以希望能够得到一个稳定可靠并且唯一的识别码.虽然Android系统中提供了这样设备识别码,但是由于Android系统版本.厂商定制系统中的Bug等限制,稳定性和唯一 ...

  8. android 获取系统硬件信息

    一,首先设置权限访问: <uses-permission android:name="android.permission.READ_PHONE_STATE" />  ...

  9. iOS开发-获取设备型号信息

    开发中有的时候查看设计统计数据,或者通过日志查看错误信息,这个时候我们就需要获取获取设备信息,看下关于设备有几种方法: NSLog(@"%@",[[UIDevice current ...

随机推荐

  1. python 代码片段5

    #coding=utf-8 # python 有两个主要数据类型:int和float.根据Kiss原则,python只有一宗整数类型int. print 3**3 print int('123') p ...

  2. Struts2 中result type属性说明

    Struts2 中result type属性说明 首先看一下在struts-default.xml中对于result-type的定义: <result-types><result-t ...

  3. 禁止ViewState的3种解决方法

    默认情况下,ViewState是被启用的,比如提交表单后,表单中输入的值会自动保留.但是如果不需要保留,也可以将其禁用,这样可以节省资源.   下面3种方式就可以分别禁用某一个控件.某一个页面和整个应 ...

  4. imread() not working in OpenCV 2.4.11 Debug mode

    The OpenCV function imread() not working in OpenCV 2.4.11 Debug mode of VS2010 under Win32, the way ...

  5. 《GK101任意波发生器》升级固件发布(版本:1.0.2build539)

    一.固件说明: 硬件版本:0,logic.3 固件版本:1.0.2.build539 编译日期:2014-10-08 ====================================== 二. ...

  6. Java集合之Map接口

    Map使用键值对来存储数据,将键映射到值对象,一个映射不能包含重复的键,每一个键最多只能映射到一个值.Map接口的具体实现类:HashMap,Hashtable,TreeMap,LinkedHashM ...

  7. OpenCV学习笔记——点击显示鼠标坐标

    点击显示鼠标显示坐标,再次点击时上一次的坐标的会消失…… #include<highgui.h> #include<cv.h> void on_mouse(int event, ...

  8. HDU 1754 I Hate It(线段树单点更新区间最值查询)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. Windows中杀死占用某个端口的进程

    Windows中杀死占用某个端口的进程 netstat -ano | findstr //列出进程极其占用的端口,且包含 80 tasklist | findstr taskkill -PID < ...

  10. Archlinux 简明安装指南

    archlinux是在distrowatch里位于top 10的发行版中,唯一采用roll release的distribution. pacman和yaourt双剑合壁,使得在archlinux安装 ...