Android Programming Tutorials

(Romina) #1
A Restaurant In Your Own Home

For now, though, just create an empty AppWidgetProvider implementation,


with the truly unique name of AppWidget:


package apt.tutorial;

import android.appwidget.AppWidgetProvider;

public class AppWidget extends AppWidgetProvider {
}

Step #4: Send the Message................................................................


As part of wiring our app widget into our application, we need to create a


"widget metadata" XML document. This file provides additional


configuration definitions for the app widget, for things that cannot readily


go into the manifest.


So, create a LunchList/res/xml/widget_provider.xml file with the following


content:


<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="300dip"
android:minHeight="79dip"
android:updatePeriodMillis="1800000"
android:initialLayout="@layout/widget"
/>

Here, we provide a height and width suggestion, which Android will


convert into a number of "cells" given the actual screen size and density.


Our height and width will give us a 4x1 cell widget, which means it will take


up the entire width of a portrait mode screen.


The metadata also indicates the starting layout to use (the one we created


earlier in this tutorial) and an "update period", which tells Android how


frequently to ask us to update the app widget's contents (set to 30 minutes,


in milliseconds).


317
Free download pdf