问题描述
我有一个AccessibilityService的宣读任何来电通知。它做工精细与ICS及以下,而不辍符合JB。
I have a AccessibilityService that shall read out any incoming notification. It does work fine with ICS and below, but stopped working with JB.
下面是清单和code:
Below are the Manifest and the code:
<service
android:name=".Services.InstantMessengerJb"
android:enabled="@bool/is_post_jb"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
tools:ignore="ExportedService" >
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
</service>
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
SettingsClass.logMe(tag, "New event!");
new AccessibilityProcessing(this, event);
}
@Override
protected void onServiceConnected() {
if (isInit) {
return;
}
SettingsClass.logMe(tag, "We are connected!");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;
setServiceInfo(info);
isInit = true;
}
正如所说它的工作在所有preJB-设备用得好好的,但是在巴顿之前启动服务(我得到了我们连),而不是一个单一事件。
As said before it does work on all preJB-Devices like a charm, however on JB the service starts (I get the "We are connected"), but not a single event is fired.
这有什么不对的code?
Is there anything wrong with the code?
推荐答案
这是我得到它的工作方式:
This is the way I got it to work:
-
子类服务类,所以有2个版本了。
Subclass the service class so there are 2 versions of it.
有在res一个bools.xml文件/目录的值,也是一个在RES /值-V16目录
Have a bools.xml file in the res/values directory and also one in the res/values-v16 directory
有一个is_jelly_bean布尔值设置为true,V16和RES一个is_not_jelly_bean /值目录版本
Have a is_jelly_bean boolean set to true in v16 and a is_not_jelly_bean in the res/values directory version
在清单中有这样的事情
<service android:name=".service.MainRunningService" android:enabled="@bool/is_jelly_bean"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter >
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibilityservice" />
</service>
<service android:name=".service.MainRunningServicePreJellyBean"
android:enabled="@bool/is_not_jelly_bean">
<intent-filter >
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibilityservice" />
</service>
有在res / xml目录呼叫accessibilityservice.xml一个辅助服务XML文件
Have an accessibility service xml file in the res/xml directory call accessibilityservice.xml
在它是这样的:
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeNotificationStateChanged"
android:accessibilityFeedbackType="feedbackSpoken"
android:notificationTimeout="100"
android:description="@string/description_that_shows_on_the_accessibility_page" />
这篇关于AccessibilityService已启动,但没有收到AccessibilityEvents的软糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!