Android Widget


Published on

Android widget

  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Android Widget

  2. 2. Topics What is an App Widget?App Widget frameworkSteps for creating an App WidgetCreating App Widgetconfiguration Activity
  3. 3. What is App Widget?Widgets are an essential aspect of home screencustomization. You can imagine them as "at-a-glance"views of an apps most important data andfunctionality that is accessible right from the usershome screen.
  4. 4. Usage Examples of App Widgets• People can drop widgets onto their homescreen and interact.• Widgets can provide a quick glimpse into fullyfeatured apps, such as showing upcomingcalendar events, or viewing details about asong playing in the background.• Users can also interact with your app throughthe widget, for example pausing or switchingmusic tracks.
  5. 5. AppWidget Framework• AppWidgetProviderInfo object> Describes the metadata for an App Widget, such asthe App Widgets layout, update frequency, and theAppWidgetProvider class.> This should be defined in XML.
  6. 6. AppWidget Framework• AppWidgetProvider class> Defines the basic methods that allow you toprogrammatically interface with the App Widget,based on broadcast events. (AppWidgetProviderclass is a child class of BroadcastReceiver class.)> Through it, you will receive broadcasts when the AppWidget is updated, enabled, disabled and deleted.
  7. 7. AppWidget Framework(cont..)• View layout> Defines the initial layout for the AppWidget, defined in XML.• Additionally, you can implement an App Widgetconfiguration Activity.
  8. 8. Steps for Building an App WidgetDeclare an AppWidgetProvider in the ManifestfileCreate the AppWidgetProviderInfo MetadataXML fileCreate the App Widget Layout XML fileWrite the AppWidgetProvider Class
  9. 9. Declare AppWidgetProvider inManifest• The <receiver> element requires the android:nameattribute, which specifies the AppWidgetProvider• The <intent-filter> element must include an <action>element with the android:name attribute. This attributespecifies that the AppWidgetProvider accepts theACTION_APPWIDGET_UPDATE broadcast.• The <meta-data> element specifies the location
  10. 10. Create AppWidgetProviderInfo Metadata• Define the AppWidgetProviderInfo object in an XMLresource using a single <appwidget-provider> elementand save it in the projects res/xml/ folder.> This file is referenced from the manifest file• Defines the essential qualities of an App Widget, suchas its minimum layout dimensions, its initial layoutresource, how often to update the AppWidget, and(optionally) a configuration Activity to launch at create time.
  11. 11. Create App Widget Layout• App Widget layouts are based on RemoteViews,which do not support every kind of layout orview widget.• A RemoteViews object (and, consequently, anApp Widget) can support the following layoutsand Widget classes
  12. 12. Write AppWidgetProvider ClassThe AppWidgetProvider class extends BroadcastReceiver asa convenience class to handle the App Widget broadcasts• Methods to override> onUpdate(Context, AppWidgetManager, int[]) - calledwhen each App Widget is added to a host (unless youuse a configuration Activity), Typically the onlymethod that needs to be present> onDeleted(Context, int[])> onEnabled(Context)>onDisabled(Context)> onReceive(Context, Intent)
  13. 13. Why App Widget Configuration Activity?• If you would like the user to configure settings when he orshe adds a new App Widget, you can create an App Widgetconfiguration Activity.• This Activity will be automatically launched by the AppWidget host and allows the user to configure available settingsfor the App Widget at create-time, such as the App Widgetcolour, size, update period or other functionality settings.
  14. 14. Declare it in Manifest File• The configuration Activity should be declared as a normalActivity in the Android manifest file.• However, it will be launched by the App Widget host withthe ACTION_APPWIDGET_CONFIGURE action, so the Activityneeds to accept this Intent<activity android:name=".ExampleAppWidgetConfigure"><intent-filter><actionandroid:name="android.appwidget.action.APPWIDGET_CONFIGURE" /></intent-filter></activity>
  15. 15. Declare it in Metadata Config file• Also, the Activity must be declared in theAppWidgetProviderInfo XML file, with the android:configureattribute<appwidget-providerxmlns:android=""""... ></appwidget-provider>
  16. 16. Thank you