package com.lcjian.library.util;
|
|
import android.app.Activity;
|
import android.content.Context;
|
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.telephony.TelephonyManager;
|
import android.view.WindowManager;
|
|
public class SystemCommon {
|
|
/**
|
* 获取deviceId
|
*
|
* @param activity
|
* @return
|
*/
|
public static String getDeviceId(Context activity) {
|
TelephonyManager manager = (TelephonyManager) activity
|
.getSystemService(Activity.TELEPHONY_SERVICE);
|
return manager.getDeviceId();
|
}
|
|
/**
|
* 获取当前APP 版本号
|
*
|
* @param activity
|
* @return
|
*/
|
public static int getVersonCode(Context activity) {
|
int versionCode = 1;
|
try {
|
versionCode = activity.getPackageManager().getPackageInfo(
|
activity.getPackageName(),
|
PackageManager.GET_CONFIGURATIONS).versionCode;// 获取app版本号
|
} catch (NameNotFoundException e) {
|
e.printStackTrace();
|
}
|
return versionCode;
|
}
|
|
/**
|
* 获取屏幕宽度
|
*
|
* @param activity
|
* @return
|
*/
|
public static float getScreenWidth(Context activity) {
|
WindowManager wm = (WindowManager) activity
|
.getSystemService(Context.WINDOW_SERVICE);
|
|
return wm.getDefaultDisplay().getWidth();
|
}
|
|
/**
|
* 获取屏幕高度
|
*
|
* @param activity
|
* @return
|
*/
|
public static float getScreenHeight(Context activity) {
|
WindowManager wm = (WindowManager) activity
|
.getSystemService(Context.WINDOW_SERVICE);
|
|
return wm.getDefaultDisplay().getHeight();
|
}
|
}
|