收到通知时如何获得通知 [英] How to get notified when a notification is notified

查看:65
本文介绍了收到通知时如何获得通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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="http://schemas.android.com/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>

享受编码.!!!:)

这篇关于收到通知时如何获得通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆