单击通知按钮后如何关闭状态栏/通知面板

编程入门 行业动态 更新时间:2024-10-24 16:23:23
本文介绍了单击通知按钮后如何关闭状态栏/通知面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我浏览了 Stackoverflow,看到有人问过这个问题,但没有找到任何解决方案.

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

我有一个带有 2 个按钮的自定义通知.我希望在按下该通知上的按钮后关闭状态栏面板,但不知道如何关闭.如果我按下通知本身(所以按下 contentIntent),面板就会关闭,这也是我想要的按钮.

I have a custom notification with 2 buttons. I want the status bar panel to close after I press a button on that notification, but don't know how. If I press the notification itself (so the contentIntent), then the panel closes, which is what I also want for my buttons.

这是我的通知代码:

Notification notification = new Notification(R.drawable.icon, "Service running", System.currentTimeMillis()); notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.contentIntent = openIntent; RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout); contentView.setOnClickPendingIntent(R.id.button1, stopIntent); contentView.setOnClickPendingIntent(R.id.button2, addIntent); notification.contentView = contentView; notificationManager.notify(NOTIFICATION_ID, notification);

推荐答案

好的,我找到了解决方案.它不是公共 API,但它有效(目前):

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 );

为了这个工作

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

需要

更多推荐

单击通知按钮后如何关闭状态栏/通知面板

本文发布于:2023-11-27 12:09:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638016.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   单击   状态栏   按钮   面板

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!