获取device的相关工具类,包括获取屏幕的高宽,dp转像素,以及手机ip,手机厂商手机型号等
public class DeviceUtil {
/**
* 获取屏幕大小
* <p>无</p>
*
* @param context 设备上下文
* @return 返回屏幕大小
*/
public static Point getDisplayMetrics(Context context) {
DisplayMetrics dm = context.getResources().getDisplayMetrics();
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
return new Point(screenWidth, screenHeight);
}
}
/**
* 获取手机型号
*/
public static String getMODEL(){
return android.os.Build.MODEL;
}
/**
* 获取手机厂商
*/
public static String getBrand(){
return android.os.Build.MANUFACTURER;
}
/**
* 获取ip
* @return
*/
public static String getIP(Context context){
//获取wifi服务
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
//判断wifi是否开启
if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
}
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
String ip = intToIp(ipAddress);
return ip;
}