android获取版本信息、屏幕信息和设备编号
2014-08-01 12:21
429 查看
1、获取版本信息:
2、获取屏幕信息
3、获取设备编号
3.1、基本上,所有设备通过((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();获取一个设备编号。但是某些平板电脑会返回空。
3.2、通过 Secure.getString(s_instance.getContentResolver(), Secure.ANDROID_ID); 会返回一个android系统唯一区分的64-bit 哈希字符串。但是android2.2或者是某些山寨手机使用这个也是有问题的,它会返回一个固定的值 9774d56d682e549c。
3.3、如果用户链接上Wi-Fi,则可以获取用户的MacAddress。
3.4、如果前两个都没有获取到udid,那么就在程序启动的时候创建一个随机的uuid,然后保存起来。这个算是兼容方案,当然这样的设备并不会很多。
/** * 获取version */ try { PackageInfo info=getPackageManager().getPackageInfo(this.getPackageName(), 1); Log.i("info","info.versionCode:"+info.versionCode); Log.i("info","info.versionName:"+info.versionName); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }
2、获取屏幕信息
/** * 获取屏幕信息 */ DisplayMetrics dm=getResources().getDisplayMetrics(); Log.i("info","widthPixels:"+dm.widthPixels); Log.i("info","heightPixels:"+dm.heightPixels);
3、获取设备编号
public static String getDeviceId(Context context) { String deviceId = null; deviceId = ((TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); if (deviceId == null && Build.VERSION.SDK_INT > 9) { deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (deviceId == null) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isAvailable() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { WifiManager wm = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); deviceId = wm.getConnectionInfo().getMacAddress(); } else { deviceId = UUID.randomUUID().toString(); } } } if (deviceId != null && deviceId.length() < 28) { int len = 28 - deviceId.length(); for (int i = 0; i < len; i++) { deviceId = "0" + deviceId; } } return deviceId; }
3.1、基本上,所有设备通过((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();获取一个设备编号。但是某些平板电脑会返回空。
3.2、通过 Secure.getString(s_instance.getContentResolver(), Secure.ANDROID_ID); 会返回一个android系统唯一区分的64-bit 哈希字符串。但是android2.2或者是某些山寨手机使用这个也是有问题的,它会返回一个固定的值 9774d56d682e549c。
3.3、如果用户链接上Wi-Fi,则可以获取用户的MacAddress。
3.4、如果前两个都没有获取到udid,那么就在程序启动的时候创建一个随机的uuid,然后保存起来。这个算是兼容方案,当然这样的设备并不会很多。
相关文章推荐
- android 系统版本信息工具类 获取设备型号 设置屏幕亮度 软键盘 获取屏幕高度宽度
- javascript获取Android设备版本信息(备忘)
- 不同Android版本设备正确获取屏幕分辨率的通用方法
- iOS如何获取屏幕宽高、设备型号、系统版本信息
- iOS获取屏幕宽高、设备型号、系统版本信息
- Android 获取设备常用信息 (app版本信息 签名信息)
- javascript获取Android设备版本信息
- 不同Android版本设备正确获取屏幕分辨率的通用方法
- iOS获取屏幕宽高、设备型号、系统版本信息
- Android开发之获取设备的屏幕信息
- 如何获取设备上运行的android版本信息
- 不同Android版本设备正确获取屏幕分辨率的通用方法
- 【Android】获取设备型号、SDK版本及其系统版本
- Android 获取程序版本信息
- android 安卓APP获取手机设备信息和手机号码的代码示例
- 获取进程信息和设备信息(包括设备类型,序列号,ios版本等
- android安卓APP获取手机设备信息和手机号码的代码示例
- 【Android】获取设备的基本服务信息
- android 获取设备屏幕尺寸、高度、宽度
- Android上获取设备的信息