Create a Service in Android with Macroid using Contexts

69 views
Skip to first unread message

Javi Pacheco

unread,
Dec 11, 2014, 10:54:44 AM12/11/14
to mac...@googlegroups.com
I'm trying to create several Views inside a Graphic Service with the SYSTEM_ALERT_WINDOW permission. I want to create view using getUi(...) but I need AppContext and ActivityContext implicit

I can't add "Contexts[Service]" in my Service. Is there some way for I can create views using macroid inside a service?

Thanks!

Nick Stanchenko

unread,
Dec 11, 2014, 11:09:54 AM12/11/14
to mac...@googlegroups.com
Hi,

For AppContext you can use

implicit lazy val appCtx = AppContext(getApplicationContext)

Unfortunately, Macroid does not support anything other than ActivityContext for creating GUI elements. So while it is theoretically possible to use the service’s context with that permission set, there is no way to construct an ActivityContext from it.

The short-term solutions would be either to create a temporary Activity and manipulate the GUI from there, or to use the native API. The long-term solution — I guess — is to create the notion of ServiceContext or somehow expand ActivityContext and overload w, l, dialog, etc, to support that. Feel free to file an issue demanding the latter approach :)

Nick
I'm trying to create several Views inside a Graphic Service with the SYSTEM_ALERT_WINDOW permission. I want to create view using getUi(...) but I need AppContext and ActivityContext implicit

I can't add "Contexts[Service]" in my Service. Is there some way for I can create views using macroid inside a service?

Thanks!
--
You received this message because you are subscribed to the Google Groups "macroid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to macroid+u...@googlegroups.com.
To post to this group, send email to mac...@googlegroups.com.
Visit this group at http://groups.google.com/group/macroid.
To view this discussion on the web visit https://groups.google.com/d/msgid/macroid/e03d1e84-00a1-4d14-b68c-df4daa491653%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Javi Pacheco

unread,
Dec 12, 2014, 3:06:39 AM12/12/14
to mac...@googlegroups.com
Yeah. I was working on ServicesContext[Service] with AppContext and a new ServiceContext implicit, but ActivityContext isn't possible inside a Service

For now, I have created a new utility in my project and I can create Option[W] from layouts easily, then I can use runUi() inside my views

Thanks Nick!
Reply all
Reply to author
Forward
0 new messages