I fixed that issue with following snippet. But this is not recommended to use. This can be achieved with the help of reflection. In future this may be deprecated.
void collapseStatusBar(Context context) { // Get access to system status bar. This is not public so may be // deprecated in the future Object service = context.getSystemService("statusbar");
Class<?> statusbarManager = null;
try {
statusbarManager = Class.forName("android.app.StatusBarManager");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.getMessage();
}
// Till 4.1 (JB), StatusBarManager collapse method did the job but from
// 4.2 it's been
// changed to collpasePanels, so perform the job accordingly
if (Build.VERSION.SDK_INT <= 16) {
Method collapseMethod = null;
try {
collapseMethod = statusbarManager.getMethod("collapse");
} catch (NoSuchMethodException e) {
e.getMessage();
}
collapseMethod.setAccessible(true);
try {
collapseMethod.invoke(service);
} catch (IllegalArgumentException e) {
e.getMessage();
} catch (IllegalAccessException e) {
e.getMessage();
} catch (InvocationTargetException e) {
e.getMessage();
}
} else {
Method collapsePanelsMethod = null;
try {
collapsePanelsMethod = statusbarManager
.getMethod("collapsePanels");
} catch (NoSuchMethodException e1) {
e1.getMessage();
}
collapsePanelsMethod.setAccessible(true);
try {
collapsePanelsMethod.invoke(service);
} catch (IllegalArgumentException e) {
e.getMessage();
} catch (IllegalAccessException e) {
e.getMessage();
} catch (InvocationTargetException e) {
e.getMessage();
}
}
}