I need after clicking on the button that is attached to push notification so that the StatusBar minimized.

For 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 immediately after the user presses the button:

 mNotificationManager.cancel(0); Log.e("!!!!!!!!!!!!!!!!!!!!", "!!!!!!!!!!!!!!!!!!!!! 1"); expandStatusBar(context); new ModelViewer(context).openFileIfAvailable(); 

Tested and everything goes in the logs 1,2,3,4 , but the curtain does not fold ...

But in the code it emphasizes this line:

 Object service = context.getSystemService("statusbar"); 

and says that the "statusbar" is not like that ... You need to choose from Context.smth_else and choose Context.NOTIFICATION_SERVICE , but it still does not work ...

I tried to do this:

 Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 

context.sendBroadcast (it);

But it also does not work ...

Tell me, what am I doing wrong?

  • The author wrote: it is hacky :) Maybe it just does not work anymore. Three years ago it worked. Such tricks should be avoided. - Eugene Krivenja
  • @EugeneKrivenja Well, I hope that it still works) Maybe I just missed something ... But I tried the more correct way new Intent (Intent.ACTION_CLOSE_SYSTEM_DIALOGS); But he still doesn’t want ... - Aleksey Timoshchenko

1 answer 1

Here's what you do wrong:

  1. Write the log only BEFORE calling the critical section of the code
  2. Silence exceptions without even logging anything.

How then to be sure that the code is generally executed?