移动开发中我们常常会需要获取用户手机上的一些特定信息,如手机卡序列号,手机的imei等等:
/**
* 判断当前设备是手机还是平板
*
* @param context
* @return 平板返回 True,手机返回 False
*/
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
/**
* 获取手机卡序列号
*/
public static String getSerialNumber() {
String serial = null;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ro.serialno");
} catch (Exception e) {
e.printStackTrace();
}
return serial;
}
/**
* 获取手机imei码
* <p/>
* 手机唯一的标识
*/
public static String getIMEI(Context mContext) {
return ((TelephonyManager) mContext
.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
}
/**
* 获得设备的padid
*/
public static String getAndroidId(Context mContext) {
return android.provider.Settings.Secure.getString(
mContext.getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID);
}
/**
* 获取手机卡号码
*/
public static String getSimSerialNumber(Context mContext) {
return ((TelephonyManager) mContext
.getSystemService(Context.TELEPHONY_SERVICE))
.getSimSerialNumber();
}
/**
* 获取手机imsi
*/
public static String getImsiNumber(Context mContext) {
return ((TelephonyManager) mContext
.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId();
}
上述便是我工具类中对于手机部分的方法,希望对大家有用,帮助大家更好的开发。