package com.doumee.keyCabinet.utils;
|
|
import android.annotation.SuppressLint;
|
import android.content.Context;
|
import android.graphics.Point;
|
import android.os.Build;
|
import android.provider.Settings;
|
import android.telephony.TelephonyManager;
|
import android.text.TextUtils;
|
import android.view.Display;
|
import android.view.WindowManager;
|
|
import com.doumee.keyCabinet.MApplication;
|
|
/**
|
*
|
* @version 1.1.5
|
*
|
*/
|
public class LMobileInfo {
|
/**
|
* 判断手机号码是否正确
|
*
|
* @param mobiles
|
* @return
|
*/
|
public static boolean isMobileNO(String mobiles) {
|
// Pattern p = Pattern
|
// .compile("^((13[0-9])|(17[0,5-8])|(15[^4,\\D])|(18[0-9]))\\d{8}$");
|
// Matcher m = p.matcher(mobiles);
|
// return m.matches();
|
return true;
|
}
|
|
/**
|
* 获取IMEI码
|
*
|
* @return
|
*/
|
public static String getImei() {
|
TelephonyManager mTm = (TelephonyManager) MApplication.mContext.getSystemService(Context.TELEPHONY_SERVICE);
|
return mTm.getDeviceId();
|
}
|
|
/**
|
* 获取IMSI码
|
*
|
* @return
|
*/
|
public static String getImsi() {
|
TelephonyManager mTm = (TelephonyManager) MApplication.mContext.getSystemService(Context.TELEPHONY_SERVICE);
|
return mTm.getSubscriberId();
|
}
|
|
/**
|
* @Description: 获取手机屏幕宽高
|
*/
|
@SuppressLint("NewApi")
|
public static Point getDeviceSize() {
|
Point deviceSize = null;
|
if (deviceSize == null) {
|
deviceSize = new Point(0, 0);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
|
((WindowManager) MApplication.mContext
|
.getSystemService(Context.WINDOW_SERVICE))
|
.getDefaultDisplay().getSize(deviceSize);
|
} else {
|
Display display = ((WindowManager) MApplication.mContext.getSystemService(Context.WINDOW_SERVICE))
|
.getDefaultDisplay();
|
deviceSize.x = display.getWidth();
|
deviceSize.y = display.getHeight();
|
display = null;
|
}
|
}
|
return deviceSize;
|
}
|
|
/**
|
* 获取Android设备的唯一标识字符串
|
*
|
* @param
|
* @return
|
*/
|
public static String getDeviceUniqueId() {
|
String uniqueId = "";
|
try {
|
// 3、获取imei
|
TelephonyManager telephonyMgr = (TelephonyManager) MApplication.mContext
|
.getSystemService(Context.TELEPHONY_SERVICE);
|
uniqueId = telephonyMgr.getDeviceId();
|
if (TextUtils.isEmpty(uniqueId)) {
|
uniqueId = getDevUUID(MApplication.mContext);
|
}
|
}catch (Exception e){
|
uniqueId=getDevUUID(MApplication.mContext);
|
}
|
|
|
// // 1、获取mac地址
|
// WifiManager wifiMgr = (WifiManager) LApplication.getInstance()
|
// .getContext().getSystemService(Context.WIFI_SERVICE);
|
// WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
|
// if (wifiInfo != null) {
|
// uniqueId = wifiInfo.getMacAddress();
|
// }
|
// if (!TextUtils.isEmpty(uniqueId)) {
|
// return uniqueId;
|
// }
|
//
|
// // 2、获取android_id
|
// uniqueId = Secure.getString(LApplication.getInstance().getContext()
|
// .getContentResolver(), Secure.ANDROID_ID);
|
// if (!TextUtils.isEmpty(uniqueId)) {
|
// return uniqueId;
|
// }
|
|
return uniqueId;
|
}
|
|
public static String getDevUUID(Context mContext) {
|
/*TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
|
String imei = telephonyManager.getDeviceId();
|
String simNo = telephonyManager.getSimSerialNumber();
|
|
WifiManager wm = (WifiManager) LApplication
|
.getInstance().getContext()
|
.getSystemService(Context.WIFI_SERVICE);
|
String wifiAddress = wm.getConnectionInfo().getMacAddress();
|
*/
|
String uniqueId="866102023684372";
|
try {
|
String androidId = "" + android.provider.Settings.Secure.getString(mContext.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
|
String ints="";
|
for (int i = 0; i < androidId.length(); i++) {
|
ints+=formatting(androidId.substring(i, i + 1));
|
}
|
if(ints.length()>=15){
|
ints=ints.substring(0,15);
|
uniqueId = ints;
|
}
|
}catch (Exception e){
|
int i=0;
|
}
|
return uniqueId;
|
}
|
|
public static String formatting(String a) {
|
int chr=a.charAt(0);
|
if(chr>47 && chr<58){
|
return a;
|
}
|
int i = 0;
|
|
if (a.equals("a")) {
|
i = 0;
|
}else if (a.equals("b")) {
|
i = 1;
|
}else if (a.equals("c")) {
|
i = 2;
|
}else if (a.equals("d")) {
|
i = 3;
|
}else if (a.equals("e")) {
|
i = 4;
|
}else if (a.equals("f")) {
|
i = 5;
|
}
|
return i+"";
|
}
|
|
public static String getAndroidId(){
|
try {
|
return Settings.Secure.getString(MApplication.mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
|
}catch (Exception e){
|
return "";
|
}
|
}
|
|
/**
|
*
|
* Description:获取运营商名称
|
*
|
* @return
|
*/
|
public static String getProvidersName() {
|
String ProvidersName = "";
|
try {
|
TelephonyManager telephonyManager = (TelephonyManager) MApplication.mContext
|
.getSystemService(Context.TELEPHONY_SERVICE);
|
// 返回唯一的用户ID;就是这张卡的编号神马的
|
String IMSI = telephonyManager.getSubscriberId();
|
// IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
|
if (!TextUtils.isEmpty(IMSI)) {
|
if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
|
ProvidersName = "中国移动";
|
} else if (IMSI.startsWith("46001")) {
|
ProvidersName = "中国联通";
|
} else if (IMSI.startsWith("46003")) {
|
ProvidersName = "中国电信";
|
}
|
}
|
}catch (Exception e){
|
|
}
|
return ProvidersName;
|
}
|
|
/**
|
* 获取厂商
|
*
|
* @return
|
*/
|
public static String getManufacturer() {
|
return android.os.Build.MANUFACTURER; // 厂商
|
}
|
|
/**
|
* 获取手机型号
|
*
|
* @return
|
*/
|
public static String getMobileType() {
|
return android.os.Build.MODEL; // 手机型号
|
}
|
|
/**
|
* 获取系统发布版本号
|
*
|
* @return
|
*/
|
|
public static String getVersionRelease() {
|
return android.os.Build.VERSION.RELEASE;
|
}
|
|
/**
|
* 终端设备编码
|
*/
|
public static final String TAG_END_FROM = "Android";
|
|
}
|