android获取手机基本信息
来源:互联网 发布:不吃乐乎什么意思 编辑:程序博客网 时间:2024/05/17 08:10
有时候我们需要获取手机设备的一下信息就可以使用如下方法:
//得到当前手机设备名称private String getPhoneInfo() { StringBuffer phoneI签: " + android.os.Build.TAGS) ; phoneInfo.append("\n手机型号: " + android.os.Build.MODEL); phoneInfo.append("\nSDK版本: " + android.os.Build.VERSION.SDK); phoneInfo.append ("\n系统版本: " + android.os.Build.VERSION.RELEASE); phoneInfo.append ("\n设备驱动: " + android.os.Build.DEVICE); phoneInfo.append("\n版本号: " + android.os.Build.DISPLAY); phoneInfo.append("\n品牌: " + android.os.Build.BRAND); phoneInfo.append("\n主板: " + android.os.Build.BOARD); phoneInfo.append("\n指纹: " + android.os.Build.FINGERPRINT); phoneInfo.append("\nID: " + android.os.Build.ID); phoneInfo.append("\n制造商: " + android.os.Build.MANUFACTURER); phoneInfo.append("\n用户组: " + android.os.Build.USER); return phoneInfo.toString();}
然后直接调用这个方法去获取即可。
同时不要忘记:
在manifest.xml文件中要添加 <uses-permission Android:name="android.permission.READ_PHONE_STATE" />权限
自己也整理了一下:
public class DeviceInfoUtil { /** * 获取android当前可用内存大小 */ private String getAvailMemory() {// 获取android当前可用内存大小 ActivityManager am = (ActivityManager)BaseApplication.getContext().getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); am.getMemoryInfo(mi); //mi.availMem; 当前系统的可用内存 return Formatter.formatFileSize(BaseApplication.getContext(), mi.availMem);// 将获取的内存大小规格化 } /** * 获得系统总内存 */ private String getTotalMemory() { String str1 = "/proc/meminfo";// 系统内存信息文件 String str2; String[] arrayOfString; long initial_memory = 0; try { FileReader localFileReader = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader( localFileReader, 8192); str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小 arrayOfString = str2.split("\\s+"); for (String num : arrayOfString) { LoggerUtil.i(str2, num + "\t"); } initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte localBufferedReader.close(); } catch (IOException e) { } return Formatter.formatFileSize(BaseApplication.getContext(), initial_memory);// Byte转换为KB或者MB,内存大小规格化 } /** * 获取IMEI号,IESI号,手机型号 */ public static void getInfo() { TelephonyManager mTm = (TelephonyManager)BaseApplication.getContext().getSystemService(BaseApplication.getContext().TELEPHONY_SERVICE); String imei = mTm.getDeviceId();//IMEI 国际移动设备识别码 String imsi = mTm.getSubscriberId();//IMSI 国际移动用户识别码 String mtype = android.os.Build.MODEL; // 手机型号 String mtyb= android.os.Build.BRAND;//手机品牌 String release=android.os.Build.VERSION.RELEASE;//系统版本 String display=android.os.Build.DISPLAY;//版本号 String numer = mTm.getLine1Number(); // 手机号码,有的可得,有的不可得 mtype=mtype.replace(" ","");//去掉空格
LoggerUtil.i("DeviceInfo", "手机IMEI号:"+imei +"\n手机IMSI号:" +imsi +"\n手机型号:"+mtype +"\n系统版本:"+release +"\n版本号:"+display +"\n手机品牌:"+mtyb +"\n手机号码:"+numer); } /** * .获取手机MAC地址 * 只有手机开启wifi才能获取到mac地址 */ private String getMacAddress(){ String result = ""; WifiManager wifiManager = (WifiManager) BaseApplication.getContext().getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); result = wifiInfo.getMacAddress(); LoggerUtil.i("text", "手机macAdd:" + result); return result; } /** * 手机CPU信息 */ private String[] getCpuInfo() { String str1 = "/proc/cpuinfo"; String str2 = ""; String[] cpuInfo = {"", ""}; //1-cpu型号 //2-cpu频率 String[] arrayOfString; try { FileReader fr = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader(fr, 8192); str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); for (int i = 2; i < arrayOfString.length; i++) { cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " "; } str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); cpuInfo[1] += arrayOfString[2]; localBufferedReader.close(); } catch (IOException e) { } LoggerUtil.i("text", "cpuinfo:" + cpuInfo[0] + " " + cpuInfo[1]); return cpuInfo; }}
阅读全文
0 0
- 获取android手机基本信息
- android获取手机基本信息
- 获取android手机基本信息
- 获取android手机基本信息
- android获取手机基本信息
- Android获取手机的基本信息
- Android开发(42) 获取android手机基本信息
- Android 获取手机的一些基本信息
- Android 获取手机的一些基本信息类
- Android 获取手机基本信息,版本号,制造商,
- 获取手机基本信息
- android Build手机基本信息
- 安卓学习笔记---【Android】获取手机的基本信息
- Android中获取手机联系人的基本信息的实现
- Android获取系统基本信息
- 获取Android设备基本信息
- Android:获取应用基本信息
- 获取手机基本信息的工具类
- Linux下串口通信详解(上)打开串口和串口初始化详解
- Unity3D相机切换效果
- K近邻算法(K-Nearest Neighbor)
- BZOJ 3991 洛谷P3320 [SDOI2015]寻宝游戏
- Qt笔记——三步设置Qt应用程序图标
- android获取手机基本信息
- R语言-数据结构
- 《写给那些想做程序员和不想做程序员的人》
- imgproc模块—仿射变换
- 堆排序
- tensorflow构造第一个神经网络
- 深度学习理解(一)
- uva题目笔记
- start和run方法区别