Question:
I need after clicking on the button that is attached to the push notification
for the StatusBar
collapse.
To do this, I found this method.
private void expandStatusBar(Context context){
Log.e("!!!!!!!!!!!!!!!!!!!!", "!!!!!!!!!!!!!!!!!!!!! 2");
try
{
Log.e("!!!!!!!!!!!!!!!!!!!!", "!!!!!!!!!!!!!!!!!!!!! 3");
Object service = context.getSystemService("statusbar");
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
if (Build.VERSION.SDK_INT <= 16)
{
Log.e("!!!!!!!!!!!!!!!!!!!!", "!!!!!!!!!!!!!!!!!!!!! 4");
Method collapse = statusBarManager.getMethod("collapse");
collapse.setAccessible(true);
collapse.invoke(service);
}
else
{
Log.e("!!!!!!!!!!!!!!!!!!!!", "!!!!!!!!!!!!!!!!!!!!! 5");
Method collapse2 = statusBarManager.getMethod("collapsePanels");
collapse2.setAccessible(true);
collapse2.invoke(service);
}
}catch(Exception ignored){}
}
I launch it right after the user clicks on the button:
mNotificationManager.cancel(0);
Log.e("!!!!!!!!!!!!!!!!!!!!", "!!!!!!!!!!!!!!!!!!!!! 1");
expandStatusBar(context);
new ModelViewer(context).openFileIfAvailable();
I tested it and everything goes through 1,2,3,4
in the logs, but the curtain does not collapse …
But in the code it underlines this line:
Object service = context.getSystemService("statusbar");
and says that "statusbar" – there is no such thing … You need to select from Context.smth_else
and select Context.NOTIFICATION_SERVICE
, but still does not work …
Tried it like this:
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
context.sendBroadcast (it);
But it doesn't work either …
Tell me what I'm doing wrong?
Answer:
Here's what you're doing wrong:
- Write the log only BEFORE calling the critical section of the code
- Suppress exceptions without even logging anything
How then can you be sure that the code is executed at all?