How to close the status bar/notification panel after notification button click

前端 未结 2 664
逝去的感伤
逝去的感伤 2020-12-05 02:17

I\'ve browsed through Stackoverflow and have seen that this question has been asked, but I didn\'t find any solution.

I have a custom notification with 2 buttons. I

相关标签:
2条回答
  • 2020-12-05 03:17

    Ok I've found the solution. It's not public API, but it works (for the moment):

    Object sbservice = c.getSystemService( "statusbar" );
                        Class<?> statusbarManager = Class.forName( "android.app.StatusBarManager" );
                        Method hidesb = statusbarManager.getMethod( "collapse" );
                        hidesb.invoke( sbservice );
    

    For this to work

    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
    

    is needed

    0 讨论(0)
  • 2020-12-05 03:18

    Use the following two code line to collapse the notification bar.

    Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    context.sendBroadcast(it);
    
    0 讨论(0)
提交回复
热议问题