I'm in an android foreground service for my own li...
# compose-android
c
I'm in an android foreground service for my own little proof of concept app. I'm trying to draw over other apps (I have that permission granted as well) Doing this crashes
Copy code
overlayView = ComposeView(context).apply {
  setContent {
    Text("Overlay Text", Modifier.padding(16.dp))
  }
}
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
windowManager.addView(overlayView, params)
with
ViewTreeLifecycleOwner not found
but if I do the same code from View land then no crash. (view system code inside 🧵 ) let me know if compose just has some weird restrictions where it can't draw like that.
If I just swap it out with the view based code then no crash. something like the below works
Copy code
overlayView = LinearLayout(context).apply {
  orientation = LinearLayout.VERTICAL
  gravity = Gravity.CENTER
  addView(textView)
}
b
Because you are running outside of a ComponentActivity there are a bunch of system hooks you would have to hook up manually
I bet if you do some googling you'll find a code snippet that gets it working, it should be possible but just extra work
b
Something to this effect https://stackoverflow.com/a/78102901
c
very interesting! let me give this a shot later today.
m
c
nice! Didn't know this many people were hacking around with overlay stuff
b
lol 😂 I did something for Gabb in 21 I think. Don’t have code to it anymore though :/
c
Gabb?
b
Built their messenger app (for all devices) and dialer for the new device that shipped end of last year
c
oh that looks really cool!
b
For sure. Was a fun project