Widget are application which are run on home screen for quick access and easily inform you from current situation, like clock widget, weather widget, calender widget and much more like this. Now in this tutorial we want to develop Android Home Screen Widget Analog Clock. Complete tutorials and Source code are in this tutorials . Lest enjoy the Fun !
Now Open manifest File which are looking like this
Now Cut the RED COLOR Activity Tag and and receiver tag Because Widget work like Broad Cast receiver Class.So add the following code on place of red color code of above manifest file
receiver name is the name of Java class which you extend form appWidgetProvider . and second in the
Now Right click on res folder of your project and create new folder name of xml and right click on xml folder and create new xml file widget_info.xml
Following are the code of your Widget_info
android:initialLayout=”@layout/widget_xml”>
Now We Discuss the red line of the code that is the layout of your widget just like we used layout for activity . The layout code are given below. In which we Simply add Analog Clock Control.
All of the Widget setting are complete Which are Common for every Widget you want to develop. widget are Broad cast receiver class which extend form AppWidgetProvider. Now We go to JAVA class widget.
//override desired method of this class
// onDelete()
// 0nUpdate()
// onDisable()
// onEnable()
}
We define onUpdate method and write the following code on it to complete my widget project.
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++) { int appWidgetId = appWidgetIds[i]; Intent intent = new Intent(context, Widget.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); appWidgetManager.updateAppWidget(appWidgetId, views); } }
Now our projcet is complete.
Source code are following in zip folder.