Creating the App Widget
A lot is going on when it comes to interacting with an app widget. The process of sending messages between the home app widget and your application is handled through the Android messaging system, the PendingIntent class, and the AppWidgetProvider. In this section, I demonstrate how to build each component so that you can get your first app widget up and running on your Home screen.
Implementing the AppWidgetProvider
Implementing the AppWidgetProvider is a straightforward process. Just follow these steps:
- Open Eclipse and open the Screen Brightness Toggle application.
- Add a new class to the com.dummies.android.screenbrightnesstoggle package and provide a name; I prefer to use AppWidget.java.
To add a new class, right-click com.dummies.android.screenbrightnesstoggle in the src/ folder and choose NewClass. This opens the New Java Class dialog box. In this dialog box, provide the name of the class and set its superclass to android.appwidget.AppWidgetProvider, as shown in Figure 8-3.
- Click Finish.
A new class has been added to the selected package, and the code with the name you chose should now be visible.
Communicating with the app widget
Right now, your AppWidgetProvider class has no code in it — it's an empty shell. ...
Get Android™ Tablet Application Development For Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.