带动作的Android通知和DropDown菜单

the*_*ani 11 android android-notifications notification-action

Android的谷歌应用程序有一个通知,显示当地的天气.如果您在通知上向左滑动,它会显示"时钟图标"-action(例如,贪睡),如下所示.

带有天气预报的Google通知

如果单击时钟,将打开以下下拉菜单:

带下拉菜单的通知

这是android系统的一个功能,我想在我的应用程序中实现.它应该通过通知操作打开,我想设置自定义选项,我需要获取选定的值.

有谁知道如何实现它?

nka*_*123 0

对于来自 Android oreo 的所有通知,这是标准的。

对于所有通知,您都会获得此暂停选项。如果您想为旧版 Android 设备实现相同的 ui,可以直接查看 Android oreo System UI 的源代码,从中我们可以获取 Android 8 及更高版本中的贪睡选项。

http://androidxref.com/8.1.0_r33/xref/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/NotificationSnooze.java#274

检查该字符串的使用

<!-- Notification: Snooze panel: message indicating how long the notification was snoozed for. [CHAR LIMIT=100]-->
1520    <string name="snoozed_for_time">Snoozed for <xliff:g id="time_amount" example="15 minutes">%1$s</xliff:g></string>
Run Code Online (Sandbox Code Playgroud)

http://androidxref.com/8.1.0_r33/xref/frameworks/base/packages/SystemUI/res/values/strings.xml#1519