luiisca / floaty

Apache License 2.0
0 stars 0 forks source link

research: look for an android api to display floating windows #1

Closed luiisca closed 2 weeks ago

linear[bot] commented 2 weeks ago

LUI-369 research: look for an android api to display floating windows

luiisca commented 2 weeks ago

before displaying anything over other apps I need to ensure the user explicitely grants the app with the required permission as per [android docs](https://developer.android.com/reference/android/provider/Settings#canDrawOverlays(android.content.Context).

So asked gpt for a code snippet as well as reviewed [this example repo](https://developer.android.com/reference/android/provider/Settings#canDrawOverlays(android.content.Context).

    private fun checkPermission() {
        if (!Settings.canDrawOverlays(this)) {
            val intent = Intent(
                Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:$packageName")
            )
            startActivity(intent)
        }
    }
luiisca commented 2 weeks ago

apparentely I need to use something called a service, a long running background operation. Created a simple service class and started it using startService from a material themed LargeFloatingActionButton. Services have a lifecycle just like activities, onCreate (executed on the first call to startService), onStartComand (every time startService is called), onDestroy and onBind

luiisca commented 2 weeks ago

inside a service I need to get the WindowManager instance associated with a display, to do that:

  1. Get display's UI context with createWindowContext
  2. call getSystemService on that contex

according to [the docs](https://developer.android.com/reference/android/view/WindowManager?hl=en) is better to use Presentation. gotta check it out