Android widgets
Android widgets
Android widgets:
A widget is a small gadget or
control of your android application
placed on the home screen. Widgets can
be very handy as they allow you to put
your favorite applications on your home
screen in order to quickly access them.
You have probably seen some common
widgets, such as music widget, weather
widget, clock widget etc.
Widgets could be of many types
such as information widgets, collection
widgets, control widgets and hybrid
widgets. Android provides us a complete
framework to develop our own widgets.
Widget - XML file
In order to do that, right click on
your project and create a new folder
called xml. Now right click on the newly
created folder and create a new XML
file. The resource type of the XML file
should be set to AppWidgetProvider.
Source code
Aphides-provider
Android:minWidth=”146dp”
Android:updatePeriodMillis=”0”
Android:minHeight=”146dp”
Android:initialLayout=”@layout/activity
main”>
</appwidget-provider>
EXAMPLE OF ANDROID
WIDGETS:
Here is an example demonstrating the
use of application Widget. It creates a
basic widget applications that will open
this current website in the browser.
<resources>
<string name=”app_name”>My
Application</string>
</resources>
To experiment with this example, you
need to run this on an actual device on
which internet is running.
Description steps:
1. on Deleted(Context context, int[]
appwidget)
This is called when an instance of
AppWidgetProvider is deleted.
2. on Disabled(Context context)
This is called when the last instance of
AppWidgetProvider is deleted
3. on Enabled(Context context)
This is called when an instance of
AppWidgetProvider is created.
4. on Receive(Context context, Intent
intent)
It is used to dispatch calls to the
various methods of the class
<application
Android:allowBackup=”true”
Android:icon=”@mipmap/ic_launcher”
Android:label=”@string/app_name”
Android:theme=”@style/AppTheme” >
<receiver
android:name=”.MainActivity”>
<intent-filter>
<action
android:name=”android.appwidget.action.A
PPWIDGET_UPDATE”></action>
</intent-filter>
<meta-data
android:name=”android.appwidget.provide
r”
Android:resource=”@xml/mywidget”></me
ta-data>
</receiver>
</application>
</manifest>
Note: By just changing the url in the java
file, your widget will open your desired
website in the browser.
DONE BY
M.MERINA 3rd -BCA