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

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

问题描述

我想读/门禁/登录其他应用程序解雇的通知栏上的通知。

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

我搜索意图 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?

推荐答案

终于得到了答案。!使用<一个href="http://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html#SERVICE_META_DATA"相对=nofollow> 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>

享受编码。! :)

Enjoy Coding.!!! :)

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

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