在我的应用程序中,我必须捕获新的传入电子邮件按摩通知,并在屏幕上播放描述事件的视频。
我正在使用onAccessibilityEvent(AccessibilityEvent event)
收听生成的通知。
我还使用以下代码来初始化我的AccessibilityService:
AccessibilityServiceInfo localAccessibilityServiceInfo = new AccessibilityServiceInfo();
localAccessibilityServiceInfo.eventTypes = AccessibilityEvent.TYPES_ALL_MASK; // AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
localAccessibilityServiceInfo.notificationTimeout = EVENT_NOTIFICATION_TIMEOUT_MILLIS;
localAccessibilityServiceInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_AUDIBLE; // AccessibilityServiceInfo.FEEDBACK_VISUAL;
localAccessibilityServiceInfo.flags &= AccessibilityServiceInfo.DEFAULT;
setServiceInfo(localAccessibilityServiceInfo);
但事件从未到来。 如何解决? 谢谢, 的Eyal。
答案 0 :(得分:2)
我有类似的情况,这适用于我的应用程序:
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Toast;
public class NotificationAccessibilityService 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);
}
}
在我的清单中:
<service android:name=".accessibility.NotificationAccessibilityService" android:label="@string/app_name" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
</service>
我的部分解决方案来自: Accessibility Service from StackOverflow