首页 > 关于手机系统信息的总结

关于手机系统信息的总结



获取IMEI号:

/*** 获取IMEI号* * @Description:* @param @param activity* @param @return* @return String*/public static String getIMEI(Activity activity) {TelephonyManager manager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);return manager.getDeviceId();}





获取IMSI:

/*** 获取IMSI* * @Description:* @param @param activity* @param @return* @return String*/public static String getIMSI(Activity activity) {TelephonyManager manager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);return manager.getSubscriberId();}





手机型号:

/*** 手机型号* * @Description:* @param @return* @return String*/public static String getPhoneModel() {return android.os.Build.MODEL;}





系统版本(数值):
/*** 系统版本(数值)* * @Description:* @param @return* @return int*/public static int getPhoneSdkVersionInt() {return Build.VERSION.SDK_INT;}





系统版本(字符串)

	/*** 系统版本(字符串)* * @Description:* @param @return* @return String*/public static String getPhoneSDKVersionChar() {return Build.VERSION.RELEASE;}





APP版本(字符串):
/*** @Description:APP版本(字符串)* @param @param activity* @param @return* @return String*/public static String getAppVersionChars(Activity activity) {PackageManager packageManager = activity.getPackageManager();PackageInfo packageInfo = null;try {packageInfo = packageManager.getPackageInfo(activity.getPackageName(), 0);} catch (NameNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}return packageInfo.versionName;}





APP版本(整型):

/*** APP版本(整型)* * @Description:* @param @param activity* @param @return* @return int*/public static int getAppVersionInt(Activity activity) {PackageManager packageManager = activity.getPackageManager();PackageInfo packageInfo = null;try {packageInfo = packageManager.getPackageInfo(activity.getPackageName(), 0);} catch (NameNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}return packageInfo.versionCode;}




获取外网IP(ip168不稳定。也能够用其他能正常获取到IP的url。原理几乎相同):

/*** 获取外网IP* * @Description:* @param @return* @return String*/public static String GetNetIp() {URL infoUrl = null;InputStream inStream = null;String ipLine = "";HttpURLConnection httpConnection = null;try {infoUrl = new URL("http://ip168.com/");URLConnection connection = infoUrl.openConnection();httpConnection = (HttpURLConnection) connection;int responseCode = httpConnection.getResponseCode();if (responseCode == HttpURLConnection.HTTP_OK) {inStream = httpConnection.getInputStream();BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, "utf-8"));StringBuilder strber = new StringBuilder();String line = null;while ((line = reader.readLine()) != null)strber.append(line + "
");Pattern pattern = Pattern.compile("((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?

\d))))"); Matcher matcher = pattern.matcher(strber.toString()); if (matcher.find()) { ipLine = matcher.group(); } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (inStream != null) { inStream.close(); } if (httpConnection != null) { httpConnection.disconnect(); } } catch (IOException e) { e.printStackTrace(); } } return ipLine; }



获取局网IP:

/*** 获取局网IP* * @Description:* @param @return* @return String*/public static String getLocalIpAddress() {try {Enumeration en = NetworkInterface.getNetworkInterfaces();while (en.hasMoreElements()) {NetworkInterface ni = en.nextElement();Enumeration enIp = ni.getInetAddresses();while (enIp.hasMoreElements()) {InetAddress inet = enIp.nextElement();if (!inet.isLoopbackAddress()&& (inet instanceof Inet4Address)) {return inet.getHostAddress().toString();}}}} catch (SocketException e) {// TODO Auto-generated catch blocke.printStackTrace();}return "0";}




Demo下载:https://github.com/xie2000/SystemInfoDemo



QQ交流群:6399844

转载于:https://www.cnblogs.com/jzdwajue/p/7105531.html

更多相关:

  • importjava.security.SecureRandom;importjavax.crypto.Cipher;importjavax.crypto.SecretKey;importjavax.crypto.SecretKeyFactory;importjavax.crypto.spec.DESKeySpec;//结果与DES算...

  • 题目:替换空格 请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 输入:s = "We are happy." 输出:"We%20are%20happy." 限制: 0 <= s 的长度 <= 10000 解题: 时间复杂度:O(n) 空间复杂度:O(n) class Solution { public:s...

  • 在C++11标准库中,string.h已经添加了to_string方法,方便从其他类型(如整形)快速转换成字面值。 例如: for (size_t i = 0; i < texArrSize; i++)RTX_Shader.SetInt(string("TexArr[") + to_string(i) + "]", 7 + i);...

  • Ubuntu 14.04安装并升级之后,变成楷体字体非常难看,我昨天搞了一晚上,终于理了个头绪,这里整理一下。 经过网上调研,大家的一致看法是,使用开源字体库文泉驿的微黑字体效果比较理想,甚至效果不输windows平台的雅黑字体。下面我打算微黑来美化Ubuntu 14.04. 1.安装文泉驿微黑字体库 sudo aptitude...

  • 使用string时发现了一些坑。 我们知道stl 容器并不是线程安全的,所以在使用它们的过程中往往需要一些同步机制来保证并发场景下的同步更新。 应该踩的坑还是一个不拉的踩了进去,所以还是记录一下吧。 string作为一个容器,随着我们的append 或者 针对string的+ 操作都会让string内部的数据域动态增加,而动态增加的...