Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: Cannot perform this action on a sealed instance

Tags:

android

I am trying to dismiss class 0 message dialogs which are also called system alert dialogs using AccessibilityService class. These dialogs are mainly used by SIM operators to notify the user in response to a request they made. I am trying to perform a global back action in onAccessibilityEvent() method to dismiss the dialog using the following code:

public void onAccessibilityEvent(AccessibilityEvent event) {      
    if(event.getClassName().toString().equals("android.app.AlertDialog")){
        event.setAction(AccessibilityService.GLOBAL_ACTION_BACK);
    }
}

However, I am getting an IllegalStateException. Here is the complete error log:

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)

1 Answers

Use the below:

performGlobalAction(GLOBAL_ACTION_BACK);
like image 131
Hussein mahyoub Avatar answered Nov 22 '25 07:11

Hussein mahyoub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!