android设备数统计,Android 设备屏幕数据

1、分辨率

/**

* 获取屏幕分辨率的宽

*

* @param context

* @return

*/

public static int getScreenResolutionWidth(Context context) {

Point screenPoint = new Point();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

((Activity) context).getWindowManager().getDefaultDisplay().getRealSize(screenPoint);

} else {

((Activity) context).getWindowManager().getDefaultDisplay().getSize(screenPoint);

}

return screenPoint.x;

}

/**

* 获取屏幕分辨率的高

*

* @param context

* @return

*/

public static int getScreenResolutionHeight(Context context) {

Point screenPoint = new Point();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

((Activity) context).getWindowManager().getDefaultDisplay().getRealSize(screenPoint);

} else {

((Activity) context).getWindowManager().getDefaultDisplay().getSize(screenPoint);

}

return screenPoint.y;

}

2、实际可用区域的宽高

/**

* 得到设备屏幕(可用区)的宽度

*

* @param context 上下文

* @return int

*/

public static int getScreenWidth(Context context) {

return context.getResources().getDisplayMetrics().widthPixels;

}

/**

* 得到设备屏幕(可用区)的高度

*

* @param context 上下文

* @return int

*/

public static int getScreenHeight(Context context) {

return context.getResources().getDisplayMetrics().heightPixels;

}

3、状态栏及底部导航栏的高度

/**

* 获取状态栏高度

*

* @param context

* @return

*/

public static int getStatusBarHeight(Context context) {

int statusBarHeight = 0;

try {

Class> c = Class.forName("com.android.internal.R$dimen");

Object o = c.newInstance();

Field field = c.getField("status_bar_height");

int x = (Integer) field.get(o);

statusBarHeight = context.getResources().getDimensionPixelSize(x);

} catch (Exception e) {

e.printStackTrace();

}

return statusBarHeight;

}

/**

* 获取底部导航栏高度

*

* @param context

* @return

*/

public static int getNavigationBarHeight(Context context) {

Resources resources = context.getResources();

int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");

int height = resources.getDimensionPixelSize(resourceId);

return height;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值