我正在尝试关闭0类消息对话框,这些对话框也称为使用AccessibilityService
类的系统警报对话框。这些对话框主要由SIM操作员用于通知用户响应他们所做的请求。我正尝试在onAccessibilityEvent()
方法中执行全局后退操作,以使用以下代码关闭对话框:
public void onAccessibilityEvent(AccessibilityEvent event) {
if(event.getClassName().toString().equals("android.app.AlertDialog")){
event.setAction(AccessibilityService.GLOBAL_ACTION_BACK);
}
}
但是,我得到IllegalStateException
。这是完整的错误日志:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: Cannot perform this action on a sealed instance.
at android.view.accessibility.AccessibilityRecord.enforceNotSealed(AccessibilityRecord.java:666)
at android.view.accessibility.AccessibilityEvent.setAction(AccessibilityEvent.java:810)
at com.example.class0message.RecorderService.onAccessibilityEvent(RecorderService.java:52)
at android.accessibilityservice.AccessibilityService$1.onAccessibilityEvent(AccessibilityService.java:518)
at android.accessibilityservice.AccessibilityService$IAccessibilityServiceClientWrapper.executeMessage(AccessibilityService.java:584)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:4952)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
使用以下内容:
performGlobalAction(GLOBAL_ACTION_BACK);