Java tutorial
//package com.java2s; import java.lang.reflect.Field; import android.content.Context; import android.util.Log; public class Main { public static int getStatusBarHeight(Context context) { Class c = null; Object bj = null; Field field = null; int x = 0, statusBarHeight = 0; try { c = Class.forName("com.android.internal.R$dimen"); bj = c.newInstance(); field = c.getField("status_bar_height"); x = Integer.parseInt(field.get(bj).toString()); statusBarHeight = context.getResources().getDimensionPixelSize(x); } catch (Exception e1) { e1.printStackTrace(); } return statusBarHeight; } public static Integer parseInt(Object value, Object defValue) { if (null == value) { return parseInt(defValue, 0); } try { return Integer.parseInt(value.toString()); } catch (Exception e) { Log.e("NumberFormatException", "Integer format Exception..."); return parseInt(defValue, 0); } } public static Integer parseInt(Object value) { return parseInt(value.toString(), 0); } }