Kis*_*ore 9 notifications android android-intent android-pendingintent accessibilityservice
我想读取/访问/记录其他应用程序在通知栏上触发的通知.
我搜索Intents并PendingIntents不少,但无法得到解决.
在发出任何通知时,是否需要通知我的应用程序?
或者android系统是否提供了用户级应用程序读取通知的内容?
从api 18(android 4.3)开始,它可能是:http: //developer.android.com/reference/android/service/notification/NotificationListenerService.html
非常容易使用,但用户必须手动授予应用程序权限.
终于得到了答案.!!! 使用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);
}
}
Run Code Online (Sandbox Code Playgroud)
我的清单是:
<?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>
Run Code Online (Sandbox Code Playgroud)
享受编码.!!! :)