收到通知时如何获得通知

编程入门 行业动态 更新时间:2024-10-11 23:18:47
本文介绍了收到通知时如何获得通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想读取/访问/记录其他应用程序在通知栏上触发的通知.

I want to read/access/log the notifications fired on notification bar by other applications.

我搜索了很多Intents 和PendingIntents,但没有找到解决方案.

I searched Intents and PendingIntents a lot, but couldn't get a solution.

是否需要在触发任何通知时通知我的应用程序?

Does my application need to be notified when any notification is fired?

或者android系统是否提供了一些东西来读取用户级应用程序的通知?

Or Does android system provide something to read notifications by the user-level applications?

推荐答案

终于得到答案了!!!使用 AccessibilityService

Finally got the answer.!!! Using AccessibilityService

public class NotificationService extends AccessibilityService { @Override public void onAccessibilityEvent(AccessibilityEvent event) { // TODO Auto-generated method stub. //Code when the event is caught } @Override public void onInterrupt() { // TODO Auto-generated method stub. } @Override protected void onServiceConnected() { AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.feedbackType = 1; info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; info.notificationTimeout = 100; setServiceInfo(info); } }

我的清单是:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="schemas.android/apk/res/android" package="org.test.notify" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <service android:name=".NotificationService" android:enabled="true"> <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <action android:name="android.accessibilityservice.AccessibilityService"/> </intent-filter> </service> </application> </manifest>

享受编码.!!!:)

更多推荐

收到通知时如何获得通知

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

发布评论

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

>www.elefans.com

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