我想收听传入的通知,当我检测到通知我的应用程序做了一些事情 我怎样才能做到这一点? 我搜索这个,但我找不到答案 请帮帮我
答案 0 :(得分:0)
答案 1 :(得分:0)
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>
成立here