android获取设备全部信息

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中加入相应权限

posted @ 2014-09-17 16:34  带狗狗带  Views(372)  Comments(0Edit  收藏  举报