I have a fully functioning Android widget that consists of a service provider class, the receiver class, and some other resources.
I have a separate app that I’ve successfully imported the classes and required resources for the widget into. There is a button menu (coded to the hard menu button) inside the app and I want to use a button in it to install the widget. I don’t care if the widget shows on the home page (I know you can’t do that from inside an app) I just want the widget to install and become an option on the “widgets” menu from the home screen.
I’ve tried starting the service from inside the app, I tried sending an update to the widget so it would call .OnEnabled, I tried instantiating the java classes… I’m obviously missing something and can’t figure it out from the android docs.
I know this is a really dumb question…
How can I get the serviceProvider to run and install the widget?
(Use WidgetServiceProvider.java and WidgetReceiver.java as examples)
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId())
{
...
case R.id.installWidget:
????????
break;
}
These sentences don’t really make sense to me. You say you want to use an app to put a widget on the homepage.. but then say you know you can’t do that from inside an app..
If you’re asking about how to get the widget to automatically get installed in the widget menu that is achieved through the manifest xml file.
For a full tutorial you can look here, but specific to your question you should only need to add a variant of these tags to your Application tag in your manifest xml file.
Links for tags: