Is it at all possible to create an App Widget programmatically from within an Android app itself? I’m rather lost on how to do this and Googling so far has led me to believe that it is not possible (that an App Widget and an App itself has to be separate applications).
So, would it be possible to dynamically create an App Widget from within an Android App? If not possible, how would you approach it? Thanks all!
That would depend completely upon what you mean by this.
No, an app widget most certainly can go in the same Android project as the rest of the application. In fact, usually it does.
Again, you seem to think that the world knows what you mean by “dynamically”, forcing us to guess.
An app widget, from the standpoint of code, consists of an
AppWidgetProvider, an entry in the manifest pointing to thatAppWidgetProvider, a metadata XML file, and whatever other resources you need (layouts, drawables, etc). All of that has to be written by a programmer and included in the app at compile time — you cannot “dynamically” create those things.An instance of an app widget is put on the home screen by the user, not by the programmer. Hence, a programmer cannot “dynamically” create instances of an app widget.
What the programmer can do “dynamically” is decide what is displayed inside of the app widget (e.g., current headlines for a news ticker, current song being played for a music player).