判断是否存在物理菜单键

/** 判断是否存在物理菜单键 */
protected boolean isExistMenuKey() {
boolean isExist = false;
Class<?> viewConfiguration = null;
try {
viewConfiguration = Class.forName("android.view.ViewConfiguration");
} catch (ClassNotFoundException e) {
Log.e(TAG, "", e);
return isExist;
}
if (viewConfiguration == null) {
return isExist;
}

Method getInstance = null;
Method hasMenuKey = null;
try {
Class<?> types[] = new Class[1];
types[0] = Context.class;
Class.forName("android.view.ViewConfiguration");
getInstance = viewConfiguration.getDeclaredMethod("get", types);
hasMenuKey = viewConfiguration.getMethod("hasPermanentMenuKey");
} catch (SecurityException e) {
Log.e(TAG, "", e);
return isExist;
} catch (NoSuchMethodException e) {
Log.e(TAG, "", e);
return isExist;
} catch (ClassNotFoundException e) {
Log.e(TAG, "", e);
return isExist;
}

if (getInstance == null || hasMenuKey == null) {
return isExist;
}
try {

isExist = (Boolean) hasMenuKey.invoke(getInstance.invoke(viewConfiguration, this),
new Object[] {});
} catch (IllegalArgumentException e) {
Log.e(TAG, "", e);
} catch (IllegalAccessException e) {
Log.e(TAG, "", e);
} catch (InvocationTargetException e) {
Log.e(TAG, "", e);
}
return isExist;
}

posted @ 2013-07-18 10:40  马骝  阅读(614)  评论(0编辑  收藏  举报