我已经按照 Google 的教程创建了一个 Big View Styled Notification (此处 their source code ):
在my own simple test app单击其中一个按钮后显示 toast (在应用程序中或在大通知中):
除一个小问题外,它运行良好:
单击通知中的其中一个按钮(“打开”或“闪烁”)时 - 我看不到 toast ,因为它被黑色通知 Pane 覆盖。
所以我的问题是:如何在我单击其中一个按钮后取消大通知并关闭通知 Pane ?(即不是通知内容,而是选择按钮)。
这是我在 MainActivity.java 中的通知构建代码- 那里有一个 setAutoCancel(true)
调用,但它只适用于内容区域:
Intent openIntent = new Intent(this, RegionService.class);
openIntent.setAction("open");
PendingIntent piOpen = PendingIntent.getService(this, 0, openIntent, 0);
Intent flashIntent = new Intent(this, RegionService.class);
flashIntent.setAction("flash");
PendingIntent piFlash = PendingIntent.getService(this, 0, flashIntent, 0);
mNotificationBuilder = new NotificationCompat.Builder(mContext)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(question)
.setContentText(question)
.setTicker(question)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(question))
.addAction(R.drawable.open,
getString(R.string.open_car_short),
piOpen)
.addAction(R.drawable.flash,
getString(R.string.flash_lights_short),
piFlash);
另外,我想知道为什么字符串“OPEN”和“FLASH”要大写?
更新:我试过cancel(NOTIFICATION_ID)正如 Marcin 所建议的那样(谢谢),它会关闭通知,但不会关闭通知 Pane 。所以还是看不到toasts
最佳答案
您需要使用 NotificationManager 的 cancel()
从代码中取消此通知:http://developer.android.com/reference/android/app/NotificationManager.html
关于android - 单击其中一个按钮(不是内容区域)后如何关闭大 View 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27360076/