我想在 android ics (4.0.3) 中记录所有 toasts 事件,但我无法记录任何系统事件。服务还没有开始!
根据这个问题: onAccessibilityEvent(AccessibilityEvent event) not intercepting notification
MyAccessibilityService.java
package com.test.toasts2;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Notification;
import android.os.Parcelable;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Toast;
public class MyAccessibilityService extends AccessibilityService {
public static final String TAG = "volumeMaster";
@Override
public void onAccessibilityEvent(AccessibilityEvent event)
{
Log.v(TAG, "***** onAccessibilityEvent");
Toast.makeText(getApplicationContext(), "Got event from: " + event.getPackageName(), Toast.LENGTH_LONG).show();
}
@Override
public void onInterrupt()
{
Log.v(TAG, "***** onInterrupt");
}
@Override
public void onServiceConnected()
{
Log.v(TAG, "***** onServiceConnected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.notificationTimeout = 100;
info.feedbackType = AccessibilityEvent.TYPES_ALL_MASK;
setServiceInfo(info);
}
}
Toast2Activity.java
package com.test.toasts2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class Toast2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent(this, MyAccessibilityService.class);
startService(i);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.toasts2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<service android:name=".MyAccessibilityService" android:label="@string/app_name" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
</service>
<activity
android:name=".Toast2Activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我在清单中包含了活动标签(在应用程序启动时启动服务),并且还尝试删除。没有改变。服务只是没有启动。我没有在日志猫(onServiceConected 中的 Log.v)中收到通知。
我将其编译为普通应用程序(不是系统应用程序),android 4.0.3。难道我做错了什么?
附加项目(可能是错在别处,或者我编译错了): https ://dl.dropbox.com/u/1928109/toast2.zip