All
I write a service to to update system state, and I use startForeground to put the service to foreground, also adding a notification to it. In the notification, I
find my question answered in other place:
1. Android: How to collapse status bar on android 4.2?
2. Preventing status bar expansion
first, add use permission lines to AndroidManifest.xml
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
second, use following codes to make it work:
try
{
Object service = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
if (Build.VERSION.SDK_INT <= 16)
{
Method collapse = statusbarManager.getMethod("collapse");
collapse.setAccessible(true);
collapse.invoke(service);
}
else
{
Method collapse2 = statusbarManager.getMethod("collapsePanels");
collapse2.setAccessible(true);
collapse2.invoke(service);
}
}catch(Exception ex){}
it's hacky, but it did work.