我有一个AccessibilityService,之前一直正常工作,但在开发过程中突然停止了工作。我无法找到原因,请查看我的代码并告诉我为什么它不起作用。
public class MyServicee extends AccessibilityService {
public static final String TAG = "volumeMaster";
@TargetApi(Build.VERSION_CODES.KITKAT)
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
List<CharSequence> eventText;
Log.v(TAG, "***** onAccessibilityEvent");
final int eventType = event.getEventType();
switch (eventType) {
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
break;
}
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
}
}
private String processUSSDText(List<CharSequence> eventText) {
for (CharSequence s : eventText) {
String text = String.valueOf(s);
if (true) {
return text;
}
}
return null;
}
@Override
public void onInterrupt() {
Log.v(TAG, "***** onInterrupt");
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onServiceConnected() {
Log.v(TAG, "***** onServiceConnected");
AccessibilityServiceInfo info = getServiceInfo();
info.eventTypes =
AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED
| AccessibilityEvent.TYPE_VIEW_CLICKED
| AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
info.packageNames = new String[]{"com.whatsapp"};
info.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
setServiceInfo(info);
super.onServiceConnected();
}
}
这是Manifest的相关部分:
<service android:name=".MyServicee"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:enabled="true">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data android:name="android.accessibilityservice"
android:resource="@xml/myservice" />
</service>
这是我的serviceconfig.xml文件:
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeViewClicked|typeNotificationStateChanged|typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackAllMask"
android:canRetrieveWindowContent="true"
android:accessibilityFlags="flagIncludeNotImportantViews|flagRequestFilterKeyEvents"
android:notificationTimeout="1"
android:packageNames="com.whatsapp"
android:settingsActivity="@string/app_name" />
该代码试图检测用户何时启动了通话录音服务。