3

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? :)

Jakub Pomykała
  • 2,082
  • 3
  • 27
  • 58
  • here is my understanding of your question. So you have 2 problems and they are: **1.** you have 2 widgets and you want the second one to appear bigger **2.** you have problem update data in widget. are these your problems? – lynnyilu Jan 24 '12 at 02:40

1 Answers1

10

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:

  1. 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

  2. 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"

  3. 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"

  4. 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

  5. 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

Jose_GD
  • 2,279
  • 1
  • 21
  • 34
  • It is really nice comment about different names for receivers. I've spent an hour until realized it and found you solution as prove. – Mikhail Oct 20 '12 at 12:29
  • good..+1 .is it possible to show a new layout on the same widget on widget click...same like smooth calendar.. – Ranjit Apr 18 '14 at 15:44
  • @RanjitPati it is possible, take into account that you have to rebuild the entire layout every time you make changes in its "structure". Unless you're talking about one of those pseudo-appwidgets like the ones in Samsung launcher or Go Launcher – Jose_GD Apr 21 '14 at 12:54