Android - Widgets Tutorial

<p></p> <p >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 favourite 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 e.t.c</p> <p >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.</p> <h2 >Widget - XML file</h2> <p >In order to create an application widget , first thing you need is AppWidgetProviderInfo object, which you will define in a separate widget XML file. In order to do that, right click on your project and create a new folder called<b >xml</b>. 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<b >AppWidgetProvider</b>. In the xml file, define some properties which are as follows &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="tag" >&lt;appwidget-provider</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >android:minWidth</span><span class="pun" >=</span><span class="atv" >&quot;146dp&quot;</span><span class="pln" > </span><span class="atn" >android:updatePeriodMillis</span><span class="pun" >=</span><span class="atv" >&quot;0&quot;</span><span class="pln" > </span><span class="atn" >android:minHeight</span><span class="pun" >=</span><span class="atv" >&quot;146dp&quot;</span><span class="pln" > </span><span class="atn" >android:initialLayout</span><span class="pun" >=</span><span class="atv" >&quot;@layout/activity_main&quot;</span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;/appwidget-provider&gt;</span></pre> <h2 >Widget - Layout file</h2> <p >Now you have to define the layout of your widget in your default XML file. You can drag components to generate auto xml.</p> <h2 >Widget - Java file</h2> <p >After defining layout, now create a new JAVA file or use existing one, and extend it with<b >AppWidgetProvider</b>class and override its update method as follows.</p> <p >In the update method, you have to define the object of two classes which are PendingIntent and RemoteViews. Its syntax is &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="typ" >PendingIntent</span><span class="pln" > pending </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >PendingIntent</span><span class="pun" >.</span><span class="pln" >getActivity</span><span class="pun" >(</span><span class="pln" >context</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >,</span><span class="pln" > intent</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >RemoteViews</span><span class="pln" > views </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >RemoteViews</span><span class="pun" >(</span><span class="pln" >context</span><span class="pun" >.</span><span class="pln" >getPackageName</span><span class="pun" >(),</span><span class="pln" > R</span><span class="pun" >.</span><span class="pln" >layout</span><span class="pun" >.</span><span class="pln" >activity_main</span><span class="pun" >);</span></pre> <p >In the end you have to call an update method updateAppWidget() of the AppWidgetManager class. Its syntax is &minus;</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pln" >appWidgetManager</span><span class="pun" >.</span><span class="pln" >updateAppWidget</span><span class="pun" >(</span><span class="pln" >currentWidgetId</span><span class="pun" >,</span><span class="pln" >views</span><span class="pun" >);</span><span class="pln" > </span></pre> <p >A part from the updateAppWidget method, there are other methods defined in this class to manipulate widgets. They are as follows &minus;</p> <table class="table table-bordered" > <tbody > <tr > <th >Sr.No</th> <th >Method &amp; Description</th> </tr> <tr > <td >1</td> <td ><b >onDeleted(Context context, int[] appWidgetIds)</b> <p >This is called when an instance of AppWidgetProvider is deleted.</p> </td> </tr> <tr > <td >2</td> <td ><b >onDisabled(Context context)</b> <p >This is called when the last instance of AppWidgetProvider is deleted</p> </td> </tr> <tr > <td >3</td> <td ><b >onEnabled(Context context)</b> <p >This is called when an instance of AppWidgetProvider is created.</p> </td> </tr> <tr > <td >4</td> <td ><b >onReceive(Context context, Intent intent)</b> <p >It is used to dispatch calls to the various methods of the class</p> </td> </tr> </tbody> </table> <h2 >Widget - Manifest file</h2> <p >You also have to declare the AppWidgetProvider class in your manifest file as follows:</p> <pre class="prettyprint notranslate prettyprinted" > <span class="tag" >&lt;receiver</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;ExampleAppWidgetProvider&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;action</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.appwidget.action.APPWIDGET_UPDATE&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;meta-data</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.appwidget.provider&quot;</span><span class="pln" > </span><span class="atn" >android:resource</span><span class="pun" >=</span><span class="atv" >&quot;@xml/example_appwidget_info&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;/receiver&gt;</span></pre> <h2 >Example</h2> <p >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.</p> <p >To experiment with this example, you need to run this on an actual device on which internet is running.</p> <table class="table table-bordered" > <tbody > <tr > <th >Steps</th> <th >Description</th> </tr> <tr > <td >1</td> <td >You will use Android studio to create an Android application under a package com.example.sairamkrishna.myapplication. While creating this project, make sure you Target SDK and Compile With at the latest version of Android SDK to use higher levels of APIs.</td> </tr> <tr > <td >2</td> <td >Modify src/MainActivity.java file to add widget code.</td> </tr> <tr > <td >3</td> <td >Modify the res/layout/activity_main to add respective XML components</td> </tr> <tr > <td >4</td> <td >Create a new folder and xml file under res/xml/mywidget.xml to add respective XML components</td> </tr> <tr > <td >5</td> <td >Modify the AndroidManifest.xml to add the necessary permissions</td> </tr> <tr > <td >6</td> <td >Run the application and choose a running android device and install the application on it and verify the results.</td> </tr> </tbody> </table> <p >Following is the content of the modified<b >MainActivity.java</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="kwd" >package</span><span class="pln" > com</span><span class="pun" >.</span><span class="pln" >example</span><span class="pun" >.</span><span class="pln" >sairamkrishna</span><span class="pun" >.</span><span class="pln" >myapplication</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >app</span><span class="pun" >.</span><span class="typ" >PendingIntent</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >appwidget</span><span class="pun" >.</span><span class="typ" >AppWidgetManager</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >appwidget</span><span class="pun" >.</span><span class="typ" >AppWidgetProvider</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >content</span><span class="pun" >.</span><span class="typ" >Context</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >content</span><span class="pun" >.</span><span class="typ" >Intent</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >net</span><span class="pun" >.</span><span class="typ" >Uri</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >RemoteViews</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >import</span><span class="pln" > android</span><span class="pun" >.</span><span class="pln" >widget</span><span class="pun" >.</span><span class="typ" >Toast</span><span class="pun" >;</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >class</span><span class="pln" > </span><span class="typ" >MainActivity</span><span class="pln" > </span><span class="kwd" >extends</span><span class="pln" > </span><span class="typ" >AppWidgetProvider</span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >public</span><span class="pln" > </span><span class="kwd" >void</span><span class="pln" > onUpdate</span><span class="pun" >(</span><span class="typ" >Context</span><span class="pln" > context</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >AppWidgetManager</span><span class="pln" > appWidgetManager</span><span class="pun" >,</span><span class="kwd" >int</span><span class="pun" >[]</span><span class="pln" > appWidgetIds</span><span class="pun" >)</span><span class="pln" > </span><span class="pun" >{</span><span class="pln" > </span><span class="kwd" >for</span><span class="pun" >(</span><span class="kwd" >int</span><span class="pln" > i</span><span class="pun" >=</span><span class="lit" >0</span><span class="pun" >;</span><span class="pln" > i</span><span class="pun" >&lt;</span><span class="pln" >appWidgetIds</span><span class="pun" >.</span><span class="pln" >length</span><span class="pun" >;</span><span class="pln" > i</span><span class="pun" >++){</span><span class="pln" > </span><span class="kwd" >int</span><span class="pln" > currentWidgetId </span><span class="pun" >=</span><span class="pln" > appWidgetIds</span><span class="pun" >[</span><span class="pln" >i</span><span class="pun" >];</span><span class="pln" > </span><span class="typ" >String</span><span class="pln" > url </span><span class="pun" >=</span><span class="pln" > </span><span class="str" >&quot;http://www.tutorialspoint.com&quot;</span><span class="pun" >;</span><span class="pln" > </span><span class="typ" >Intent</span><span class="pln" > intent </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >Intent</span><span class="pun" >(</span><span class="typ" >Intent</span><span class="pun" >.</span><span class="pln" >ACTION_VIEW</span><span class="pun" >);</span><span class="pln" > intent</span><span class="pun" >.</span><span class="pln" >addFlags</span><span class="pun" >(</span><span class="typ" >Intent</span><span class="pun" >.</span><span class="pln" >FLAG_ACTIVITY_NEW_TASK</span><span class="pun" >);</span><span class="pln" > intent</span><span class="pun" >.</span><span class="pln" >setData</span><span class="pun" >(</span><span class="typ" >Uri</span><span class="pun" >.</span><span class="pln" >parse</span><span class="pun" >(</span><span class="pln" >url</span><span class="pun" >));</span><span class="pln" > </span><span class="typ" >PendingIntent</span><span class="pln" > pending </span><span class="pun" >=</span><span class="pln" > </span><span class="typ" >PendingIntent</span><span class="pun" >.</span><span class="pln" >getActivity</span><span class="pun" >(</span><span class="pln" >context</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >,</span><span class="pln" >intent</span><span class="pun" >,</span><span class="pln" > </span><span class="lit" >0</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >RemoteViews</span><span class="pln" > views </span><span class="pun" >=</span><span class="pln" > </span><span class="kwd" >new</span><span class="pln" > </span><span class="typ" >RemoteViews</span><span class="pun" >(</span><span class="pln" >context</span><span class="pun" >.</span><span class="pln" >getPackageName</span><span class="pun" >(),</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >layout</span><span class="pun" >.</span><span class="pln" >activity_main</span><span class="pun" >);</span><span class="pln" > views</span><span class="pun" >.</span><span class="pln" >setOnClickPendingIntent</span><span class="pun" >(</span><span class="pln" >R</span><span class="pun" >.</span><span class="pln" >id</span><span class="pun" >.</span><span class="pln" >button</span><span class="pun" >,</span><span class="pln" > pending</span><span class="pun" >);</span><span class="pln" > appWidgetManager</span><span class="pun" >.</span><span class="pln" >updateAppWidget</span><span class="pun" >(</span><span class="pln" >currentWidgetId</span><span class="pun" >,</span><span class="pln" >views</span><span class="pun" >);</span><span class="pln" > </span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >makeText</span><span class="pun" >(</span><span class="pln" >context</span><span class="pun" >,</span><span class="pln" > </span><span class="str" >&quot;widget added&quot;</span><span class="pun" >,</span><span class="pln" > </span><span class="typ" >Toast</span><span class="pun" >.</span><span class="pln" >LENGTH_SHORT</span><span class="pun" >).</span><span class="pln" >show</span><span class="pun" >();</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span><span class="pln" > </span><span class="pun" >}</span></pre> <p >Following is the modified content of the xml<b >res/layout/activity_main.xml</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="tag" >&lt;RelativeLayout</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >xmlns:tools</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/tools&quot;</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;match_parent&quot;</span><span class="pln" > </span><span class="atn" >android:paddingLeft</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingRight</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_horizontal_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingTop</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >android:paddingBottom</span><span class="pun" >=</span><span class="atv" >&quot;@dimen/activity_vertical_margin&quot;</span><span class="pln" > </span><span class="atn" >tools:context</span><span class="pun" >=</span><span class="atv" >&quot;.MainActivity&quot;</span><span class="pln" > </span><span class="atn" >android:transitionGroup</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;TextView</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Tutorials point&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:textColor</span><span class="pun" >=</span><span class="atv" >&quot;#ff3412ff&quot;</span><span class="pln" > </span><span class="atn" >android:textSize</span><span class="pun" >=</span><span class="atv" >&quot;35dp&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > </span><span class="tag" >&lt;Button</span><span class="pln" > </span><span class="atn" >android:layout_width</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:layout_height</span><span class="pun" >=</span><span class="atv" >&quot;wrap_content&quot;</span><span class="pln" > </span><span class="atn" >android:text</span><span class="pun" >=</span><span class="atv" >&quot;Widget&quot;</span><span class="pln" > </span><span class="atn" >android:id</span><span class="pun" >=</span><span class="atv" >&quot;@+id/button&quot;</span><span class="pln" > </span><span class="atn" >android:layout_centerHorizontal</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:layout_marginTop</span><span class="pun" >=</span><span class="atv" >&quot;61dp&quot;</span><span class="pln" > </span><span class="atn" >android:layout_below</span><span class="pun" >=</span><span class="atv" >&quot;@+id/textView&quot;</span><span class="pln" > </span><span class="tag" >/&gt;</span><span class="pln" > &amp;lr;/RelativeLayout&gt;</span></pre> <p >Following is the content of the<b >res/xml/mywidget.xml</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;appwidget-provider</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >android:minWidth</span><span class="pun" >=</span><span class="atv" >&quot;146dp&quot;</span><span class="pln" > </span><span class="atn" >android:updatePeriodMillis</span><span class="pun" >=</span><span class="atv" >&quot;0&quot;</span><span class="pln" > </span><span class="atn" >android:minHeight</span><span class="pun" >=</span><span class="atv" >&quot;146dp&quot;</span><span class="pln" > </span><span class="atn" >android:initialLayout</span><span class="pun" >=</span><span class="atv" >&quot;@layout/activity_main&quot;</span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;/appwidget-provider&gt;</span></pre> <p >Following is the content of the<b >res/values/string.xml</b>.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="tag" >&lt;resources&gt;</span><span class="pln" > </span><span class="tag" >&lt;string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >&quot;app_name&quot;</span><span class="tag" >&gt;</span><span class="pln" >My Application</span><span class="tag" >&lt;/string&gt;</span><span class="pln" > </span><span class="tag" >&lt;string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >&quot;hello_world&quot;</span><span class="tag" >&gt;</span><span class="pln" >Hello world!</span><span class="tag" >&lt;/string&gt;</span><span class="pln" > </span><span class="tag" >&lt;string</span><span class="pln" > </span><span class="atn" >name</span><span class="pun" >=</span><span class="atv" >&quot;action_settings&quot;</span><span class="tag" >&gt;</span><span class="pln" >Settings</span><span class="tag" >&lt;/string&gt;</span><span class="pln" > </span><span class="tag" >&lt;/resources&gt;</span></pre> <p >Following is the content of<b >AndroidManifest.xml</b>file.</p> <pre class="prettyprint notranslate prettyprinted" > <span class="pun" >&lt;?</span><span class="pln" >xml version</span><span class="pun" >=</span><span class="str" >&quot;1.0&quot;</span><span class="pln" > encoding</span><span class="pun" >=</span><span class="str" >&quot;utf-8&quot;</span><span class="pun" >?&gt;</span><span class="pln" > </span><span class="tag" >&lt;manifest</span><span class="pln" > </span><span class="atn" >xmlns:android</span><span class="pun" >=</span><span class="atv" >&quot;http://schemas.android.com/apk/res/android&quot;</span><span class="pln" > </span><span class="atn" >package</span><span class="pun" >=</span><span class="atv" >&quot;com.example.sairamkrishna.myapplication&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;application</span><span class="pln" > </span><span class="atn" >android:allowBackup</span><span class="pun" >=</span><span class="atv" >&quot;true&quot;</span><span class="pln" > </span><span class="atn" >android:icon</span><span class="pun" >=</span><span class="atv" >&quot;@mipmap/ic_launcher&quot;</span><span class="pln" > </span><span class="atn" >android:label</span><span class="pun" >=</span><span class="atv" >&quot;@string/app_name&quot;</span><span class="pln" > </span><span class="atn" >android:theme</span><span class="pun" >=</span><span class="atv" >&quot;@style/AppTheme&quot;</span><span class="pln" > </span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;receiver</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;.MainActivity&quot;</span><span class="tag" >&gt;</span><span class="pln" > </span><span class="tag" >&lt;intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;action</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.appwidget.action.APPWIDGET_UPDATE&quot;</span><span class="tag" >&gt;&lt;/action&gt;</span><span class="pln" > </span><span class="tag" >&lt;/intent-filter&gt;</span><span class="pln" > </span><span class="tag" >&lt;meta-data</span><span class="pln" > </span><span class="atn" >android:name</span><span class="pun" >=</span><span class="atv" >&quot;android.appwidget.provider&quot;</span><span class="pln" > </span><span class="atn" >android:resource</span><span class="pun" >=</span><span class="atv" >&quot;@xml/mywidget&quot;</span><span class="tag" >&gt;&lt;/meta-data&gt;</span><span class="pln" > </span><span class="tag" >&lt;/receive&gt;</span><span class="pln" > </span><span class="tag" >&lt;/application&gt;</span><span class="pln" > </span><span class="tag" >&lt;/manifest&gt;</span></pre> <p >Let&#39;s try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from Android studio, open one of your project&#39;s activity files and click Run<img alt="Eclipse Run Icon" class="inline" src="http://www.tutorialspoint.com/android/images/eclipse_run.jpg" />icon from the tool bar. Before starting your application, Android studio will display following window to select an option where you want to run your Android application.</p> <p><img alt="Anroid Widget Tutorial" src="http://www.tutorialspoint.com/android/images/choose_device.jpg" /></p> <p >Select your mobile device as an option and then check your mobile device which will display your default screen &minus;</p> <p><img alt="Anroid Widget Tutorial" src="http://www.tutorialspoint.com/android/images/widget1.jpg" /></p> <p >Go to your widget section and add your created widget to the desktop or home screen. It would look something like this &minus;</p> <p><img alt="Anroid Widget Tutorial" src="http://www.tutorialspoint.com/android/images/widget1.jpg" /></p> <p >Now just tap on the widget button that appears, to launch the browser. But before that please make sure that you are connected to the internet. After pressing the button , the following screen would appear &minus;</p> <p><img alt="Anroid Widget Tutorial" src="http://www.tutorialspoint.com/android/images/widget2.jpg" /></p> <p >Note. By just changing the url in the java file, your widget will open your desired website in the browser.</p>
T:0.007477s,M:231.52 KB
返回顶部 留言