How to create multiple activities touch overlay app?

35 views Asked by At

Im creating overlay app that shows over some games, i want to be able to use joystick in game / scroll webpage and click my overlay buttons that are at the screen bottom. How can i achieve this?

Something like keyboard can do, you can push/hold keyboard keys, and scroll apps at the same time

Already tried WindowManager with diffrent flags, but its not working - I should be able to click my button that LOG something for example, while scrolling web page at the same time, without touch interrupting

Im granting <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> to my app, and im using this to display my overlay ` private fun startOverlayService() { mOverlayView = LayoutInflater.from(this).inflate(R.layout.overlay_layout, null)

    val params = WindowManager.LayoutParams(
        WindowManager.LayoutParams.MATCH_PARENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
        } else {
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
        },
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT
    )

    params.gravity = Gravity.TOP or Gravity.START

    mWindowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
    mWindowManager?.addView(mOverlayView, params)` 
1

There are 1 answers

0
Karol Trawa On

FLAG_SPLIT_TOUCH was the answer!

   val params = WindowManager.LayoutParams(
        WindowManager.LayoutParams.MATCH_PARENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
        PixelFormat.TRANSLUCENT
    )