How to create a widget?

I have in mind the provider in @xml/widget_info the receiver in manifest the layout of the widget and the provider class is that I have dúvida.Do what does she need to have?

 2
Author: ramaral, 2014-02-20

1 answers

To create a widget on Android you need:

  • a layout for the widget, i.e. a common layout file, which will be in the res / layout folder
  • an xml describing the properties of the widget, I. and an AppWidgetProviderInfo
  • A Class of type BroadcastReceiver to build the widget interface
  • describe the widget on your AndroidManifest.xml
  • and optionally you can use a Activity to configure something that you want when the user adds their widget on the main screen for the first time.

I learned how to make widgets by following this tutorial from Vogel, and I used this same article as a basis to answer here for you.

And answering your questions about widget_info and receiver, widget_info needs to define the layout that the widget has used, the width and height of the widget, and the rate of time your widget has received updates, i.e. how long your widget has been updated. receiver will be called. using the vogel example, follow the example of widget_info:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider 
xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget_layout"
android:minHeight="72dp"
android:minWidth="300dp"
android:updatePeriodMillis="300000" >
</appwidget-provider> 

And about receiver, your class that extends the AppWidgetProvider will have a method called onUpdate, this method will be called during the interval that you defined in widget_info and in it you can make updates to the widget, such as changing an image or a text, or any type of update that you want to put in the widget.

 3
Author: ademar111190, 2014-02-22 23:49:04