Java Android:通过代码获取所有通知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3030626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: get all the notifications by code
提问by Waza_Be
I am using some home replacement that allow me to hide the notification Bar and that's something I really like.
我正在使用一些家庭替代品,它允许我隐藏通知栏,这是我真正喜欢的东西。
All the informations can be replaced by some widgets, but I would like to display the notifications too.
所有信息都可以由一些小部件代替,但我也想显示通知。
As I already developed some applications, I would like to know if there is a command line that allow an application to get all the notifications. I plan to add this to a widget or a toast.
由于我已经开发了一些应用程序,我想知道是否有一个命令行允许应用程序获取所有通知。我打算将它添加到小部件或祝酒词中。
Thank a lot for any clue or help.
非常感谢任何线索或帮助。
采纳答案by esters
Since Android API Level 18 (Android 4.3) there is a class NotificationListenerService. You must set the Permission BIND_NOTIFICATION_LISTENER_SERVICEand use a intent-filter with the action NotificationListenerService.
从 Android API Level 18 (Android 4.3) 开始,有一个类NotificationListenerService。您必须设置权限BIND_NOTIFICATION_LISTENER_SERVICE并使用具有操作NotificationListenerService的意图过滤器。
<service android:name=".NotificationListener"
android:label="@string/service_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
来源:http: //developer.android.com/reference/android/service/notification/NotificationListenerService.html#getActiveNotifications()
回答by Waza_Be
I will answer my question because I found something on an other forum.
我会回答我的问题,因为我在其他论坛上找到了一些东西。
Seem that you can access them declaring your application as an (sorry for the french term, I couldn't find an english translation) "gestionnaire d'accessibilité" that you may translate as "accessibility manager"
似乎您可以访问它们,将您的应用程序声明为(对不起,法语术语,我找不到英文翻译)“gestionnaire d'accessibilité”,您可以将其翻译为“辅助功能管理器”
More information here: https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html
更多信息:https: //developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html
That may be dangerous and has a lot of negative point, but an other dev that is also working on a custom Home assure me that this feature work and he was able to create his own notification bar.
这可能很危险并且有很多负面影响,但是另一个也在开发自定义 Home 的开发人员向我保证此功能有效并且他能够创建自己的通知栏。