本文介绍了如何关闭状态栏/通知面板通知后,按一下按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我已经通过浏览#1,并已经看到,这个问题已经被问过,但我没有找到任何解决方案。

我有2个按钮自定义通知。我想要的状态栏面板关闭后,我preSS在该通知的按钮,但不知道怎么办。如果我preSS通知本身(所以contentIntent),然后将面板闭合,这是我也想为我的按钮。

下面是我的通知code:

 的通知的通知=新的通知(R.drawable.icon,服务运行,System.currentTimeMillis的());
notification.flags | = Notification.FLAG_ONGOING_EVENT;
notification.contentIntent = openIntent;
RemoteViews内容查看=新RemoteViews(getPackageName(),R.layout.notification_layout);


contentView.setOnClickPendingIntent(R.id.button1,stopIntent);
contentView.setOnClickPendingIntent(R.id.button2,addIntent);

notification.contentView =内容查看;

notificationManager.notify(NOTIFICATION_ID,通知);
 

解决方案

好吧,我已经找到了解决方案。这不是公共的API,但它的工作原理(暂时):

 对象sbservice = c.getSystemService(状态栏);
                    类<> statusbarManager =的Class.forName(android.app.StatusBarManager);
                    方法hidesb = statusbarManager.getMethod(崩溃);
                    hidesb.invoke(sbservice);
 

对于这个工作

 <使用-权限的Andr​​oid:名称=android.permission.EXPAND_STATUS_BAR/>
 

需要

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 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.

Here's my notification code:

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);
解决方案

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

这篇关于如何关闭状态栏/通知面板通知后,按一下按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:18