標籤:android style blog color io os 使用 ar div
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擷取裝置全部資訊