So, finally here I'm, after searching the Google and SO for this perticular problem which made me crasy from past 3 days. A lot of answers are out there but it seems that neither of them seems to solve this specific issue. Here is what I have found so far,
Android soft keyboard not working
How to hide and show Android Soft keyboard from an Accessibility Service
Window manager blocking keyboard for apps underneath floating chat head
Android: show soft keyboard automatically when focus is on an EditText
Android - Keyboard not appearing in floating window
What I want to acheive
- I want to open a screen with EditTextin it fromAccessibilityService(This part is done).
- Open keyboard and type text in the EditText.
- Take the input text from EditText(with a button click), and send it to theEditTextof Messaging App, and then perform a click event on send button in Messaging App. This all will be done usingAccessibilityServiceand not by the user.
- The overlayed screen should be removed when user expand the notification_panelor press theBack,HomeorRecentsbutton from the navigation area.
The Problem
Im unable to handle keyboard and its input on an EditText inflated using WindowManager in an AccessibilityService.
Scenarios/use cases
Scenario 1 (Image 1)
-> Inflated the view with window type TYPE_APPLICATION_OVERLAY and window flag FLAG_NOT_FOCUSABLE.
Able to acheive
- I can listen to all events in AccessibilityService.
- I can remove the overlayed window when notification_panelexpands.
- I can listen to navigation buttons, and handle the code accrodingly.
Unable to acheive
- Unable to show keyboard by clicking on EditTextor programatically.
what I have tried so far
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        chattingLayoutParams = WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT
        )
    } else {
        chattingLayoutParams = WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT
        )
    }
and this (but not working)
val imm: InputMethodManager =
            getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
        imm.showSoftInput(someEditText, InputMethodManager.SHOW_IMPLICIT)
Scenario 2 (Image 2)
-> Inflated the view with window type TYPE_APPLICATION_OVERLAY and window flag FLAG_NOT_TOUCH_MODEL.
Able to acheive
- Show keyboard and type text.
Unable to acheive
- Can not trigger events in the SccessibilityService.
- Unable to trigger the notification_panelchanges to remove overlayed window.
- Unable to trigger navigation buttons (back, home, recents) actions to remove overlayed window.
What i have tried so far
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        chattingLayoutParams = WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            PixelFormat.TRANSLUCENT
        )
    } else {
        chattingLayoutParams = WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            PixelFormat.TRANSLUCENT
        )
    }
AccessibilityService Config.xml file
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackSpoken"
android:accessibilityFlags="flagReportViewIds"
android:canRetrieveWindowContent="true"
android:notificationTimeout="100" />
I hope the problem is clear, please forgive for any inconvenience.

 
    