复制代码
public class CommonUtil {
public static boolean hasSDCard() {
String status = Environment.getExternalStorageState();
return status.equals(Environment.MEDIA_MOUNTED);
}
/**
* 获取最大内存
*
* @return
*/
public static long getMaxMemory() {
return Runtime.getRuntime().maxMemory() / 1024;
}
/**
* 检查网络
*
* @param context
* @return
*/
public static boolean checkNetState(Context context) {
boolean netstate = false;
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
netstate = true;
break;
}
}
}
}
return netstate;
}
public static void showToast(Context context, String tip) {
Toast.makeText(context, tip, Toast.LENGTH_SHORT).show();
}
public static DisplayMetrics metric = new DisplayMetrics();
/**
* 得到屏幕高度
*
* @param context
* @return
*/
public static int getScreenHeight(Activity context) {
context.getWindowManager().getDefaultDisplay().getMetrics(metric);
return metric.heightPixels;
}
/**
* 得到屏幕宽度
*
* @param context
* @return
*/
public static int getScreenWidth(Activity context) {
context.getWindowManager().getDefaultDisplay().getMetrics(metric);
return metric.widthPixels;
}
/**
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
*/
public static int dip2px(Context context, float dpValue) {










