Code snippet:
1. Get hide constant value
public static int getHideIntConstants(String classAndPkgName, String fieldName, int defaultValue){
int fieldValue = defaultValue;
Class<?> c = null;
try {
c = Class.forName(classAndPkgName);
Field field = c.getDeclaredField(fieldName);
field.setAccessible(true);
fieldValue = field.getInt(null);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
String hesString = Integer.toHexString(fieldValue);
Log.d(TAG, "fieldValue " + fieldName + ": " + fieldValue + " ; hex: " + hesString);
return fieldValue;
}
2. Get hide constant value declared in inner class
public static int getTypeDisplayOverlayInt(Window window) {
int typeDisplayOverlay = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
Class<?> c = null;
try {
c = Class.forName("android.view.WindowManager");
Class<?>[] classes = c.getDeclaredClasses();
for(Class innerClass: classes){
if(innerClass.getName().contains("LayoutParams")){
Field field = innerClass.getDeclaredField("TYPE_DISPLAY_OVERLAY");
field.setAccessible(true);
typeDisplayOverlay = field.getInt(window.getAttributes());
break;
}
}
} catch (Exception e){
e.printStackTrace();
}
return typeDisplayOverlay;
}
3. Get resource value
public static int getStatusHeight(Context context) {
int statusBarHeight = -1;
try {
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
int height = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString());
statusBarHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e) {
e.printStackTrace();
}
return statusBarHeight;
}
4. Get SystemUI apk recource value
public static String getDateFormat(Context context) {
PackageManager pm = context.getPackageManager();
try {
Resources resources = pm.getResourcesForApplication("com.android.systemui");
int id = resources.getIdentifier("abbrev_wday_month_day_no_year", "string", "com.android.systemui");
if (id > 0) {
return resources.getString(id);
} else {
return null;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return null;
}