I was searching in internet but nothing helps. I want to make second widget, just bigger. Im using service to update my widget so I need to create 2 services (update data in widget by remoteviews etc.) or can I make it easier?
When I add medium widget, it shows up te small one but it takes more space (144dp x 72dp) and there is no update. Maybe I should copy whole app classes and modify it, but I think this is stupid solution.
I was trying this solutions
how to add multiple widgets in one app?
How to put multiple widget sizes in one apk?
Any hints? :)
I had the same need with my widget. Precisely those two links you have posted helped me find the solution, which came at last with a bit more of research.
In order to have a second size for your widget:
Define another receiver in your manifest, with a diferent name. This is important: if you don't use a different name, only one will show in the list of available widgets. For example: android:name=".MyWidget_Small"
and android:name=".MyWidget_Medium"
. Also modify the labels accordingly
The additional receiver needs a new appwidget provider in res/xml. In android:resource of the meta-data tag type the name of another XML file. You'll have then android:resource="@xml/MyWidgetProvider_Small"
and android:resource="@xml/MyWidgetProvider_Medium"
Each XML file in res/xml must point to a separate layout. You will have android:initialLayout="@layout/MyWidget_Small"
and android:initialLayout="@layout/MyWidget_Medium"
Now the Java part. Each appwidget provider need its correspondent Java class that extends AppWidgetProvider, so you will need two additional classes. If your original class was MyWidget.java, you'll add MyWidgetSmall.java and MyWidgetMedium.java. You'll probably end up subclassing your original Java class, and perhaps modifing each new class if the widget has a distinct behavior in each size. Remember to name the two classes as you did in step 1 in the receivers's android:name
Your service doesn't need duplication. However you should examine your source code to find occurrences of explicit references to MyWidget.class. If you did this, you must reference the actual subclass
Hope this helps