本文共 3100 字,大约阅读时间需要 10 分钟。
获取版本号:
PackageManager packageManager = context.getPackageManager();
String st_versionCode r=packageManager.getPackageInfo(context.getPackageName(), 0).versionCode + "";
获取获得手机语言:
public String getTelephoneLanguageFromSystem(Context context) {
String language = Locale.getDefault().getLanguage();
if (language.equals("zh")) {
return "cn";
} else if (language.equals("en")) {
return "en";
} else {
return "en";
}
}
获得手机串口号码(IMEI):
public String getTelephoneIMEIFromSystem(Context context) {
TelephonyManager telMg = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return telMg.getDeviceId();
}
获得手机电话号码:
public String getTelephoneNumFromSystem(Context context) {
TelephonyManager telephoneManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephoneManager.getLine1Number() != null) {
return telephoneManager.getLine1Number();
} else {
return null;
}
}
获取手机平台版本:
String str_display=Build.DISPLAY;
手机设备版本
String str_model=Build.MODEL;
获取手机固件版本:
public String getTelphoneFirmVersionFromSystem() {
if(getTelphoneReleaseFromSys().contains("4.0")) {
return DataSourceConstants.FIRMWARE_40;
}else if (getTelphoneReleaseFromSys().contains("3.2")) {
return DataSourceConstants.FIRMWARE_32;
} else if (getTelphoneReleaseFromSys().contains("3.1")) {
return DataSourceConstants.FIRMWARE_31;
} else if (getTelphoneReleaseFromSys().contains("2.3")) {
return DataSourceConstants.FIRMWARE_23;
} else if (getTelphoneReleaseFromSys().contains("2.2")) {
return DataSourceConstants.FIRMWARE_21;
} else if (getTelphoneReleaseFromSys().contains("2.1")) {
return DataSourceConstants.FIRMWARE_21;
} else if (getTelphoneReleaseFromSys().contains("2.0")) {
return DataSourceConstants.FIRMWARE_21;
} else if (getTelphoneReleaseFromSys().contains("1.6")) {
return DataSourceConstants.FIRMWARE_15;
} else if (getTelphoneReleaseFromSys().contains("1.5")) {
return DataSourceConstants.FIRMWARE_15;
} else {
return DataSourceConstants.FIRMWARE_21;
}
}
从SIM卡获得网络码:
TelephonyManager telephoneManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
if (telephoneManager.getSimState() == TelephonyManager.SIM_STATE_READY) {
String str=telephoneManager.getSimOperator();
String netCode=str.subString(3,str.length);
} else
return null;
获得设备屏幕的大小:
public static String getTelphoneScreenFromSystem(Context context) {
Configuration config = context.getResources().getConfiguration();
if ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
return "xlarge";
}else if((config.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE){
return "large";
}else if ((config.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
return "small";
}else if ((config.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
return "normal";
}else if ((config.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
return "normal";
}else {
return "normal";
}
}
转载地址:http://icnzx.baihongyu.com/