Friday, March 18, 2011

Hello World Widget in Android

In this exercise, a dummy home screen app widget will be described; to show the
simpliest element of a ndroid app widget.

- Create a new project of android application as normal, HelloWidget.

- Modify AndroidManifest.xml to have a receiver, with name of "HelloWidgetProvider", under Appliation.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.exercise.HelloWidget"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
  <activity android:name=".HelloWidget"

            android:label="@string/app_name">
      <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />

      </intent-filter>
  </activity>
 <receiver android:name="HelloWidgetProvider" >
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

    </intent-filter>
    <meta-data android:name="android.appwidget.provider"
     android:resource="@xml/hellowidgetproviderinfo" />
 </receiver>
</application>

<uses-sdk android:minSdkVersion="4" />

</manifest>

The element requires the android:name attribute, which specifies the AppWidgetProvider used by the App Widget.

The element must include an element with the android:name attribute. This attribute specifies that the AppWidgetProvider accepts the ACTION_APPWIDGET_UPDATE broadcast.

The element specifies the AppWidgetProviderInfo resource and requires the following attributes:

* android:name - Specifies the metadata name. Use android.appwidget.provider to
identify the data as the AppWidgetProviderInfo descriptor.

* android:resource - Specifies the AppWidgetProviderInfo resource location.

- Create a new folder /res/xml, create a new hellowidgetproviderinfo.xml

 
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dp"
android:minHeight="72dp"
android:updatePeriodMillis="10000"
android:initialLayout="@layout/hellowidget_layout"
>
</appwidget-provider>

It define the AppWidgetProviderInfo object in an XML resource using a single , include the essential qualities of an App Widget, such as its minimum layout dimensions, its initial layout resource, how often to update the App Widget, and (optionally) a configuration Activity to launch at create-time.

- Create a layout file /res/layout/hellowidget_layout.xml
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"

/>
</LinearLayout>

It's the layout of the widget. In this dummy exercisse, just copy the content of the auto-generated layout, main.xml.

- Create a class HelloWidgetProvider.java extends AppWidgetProvider. With nothing inside.


package com.exercise.HelloWidget;

import android.appwidget.AppWidgetProvider;

public class HelloWidgetProvider extends AppWidgetProvider {

}

It do nothing at all. Now you can build and Install the application as normal, then close it after started.
It's not own target in this exercise.

- Add the HelloWidget on Home Screen. It's
a dummy widget without any function, just show how to create a app widget.

28 comments:

  1. Many inspirational stuff here in this post. Never knew that opinions could be this varied. Thanks for all the enthusiasm to offer such helpful information here.
    App Development Company

    ReplyDelete
  2. Thanks for sharing, I will bookmark and be back again


    Android Application Development

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. A debt of gratitude is in order regarding gathering and imparting such pleasant assets for portable include engineers or any one who is intrigued by application improvement. I might like to include two other significant application stage.
    Build Android App // Mobile
    Application Development
    // Android Application Development

    ReplyDelete
  5. We offer cross platform mobile solutions including SIP dialer to Android Application Development Company worldwide clients. We specialize in the development of business apps for iOS, Android, Windows, and SmartPhones.

    ReplyDelete
  6. This blog is impressive and informative.It clearly explains about the concept and its techniques.Thanks for sharing this information.Please update this type of information
    android Training in Chennai

    ReplyDelete
  7. Nice it seems to be good post... It will get readers engagement on the article since readres engagement plays an vital role in every blog.. i am expecting more updated posts from your hands.
    iOS Training in Chennai
    Android Training in Chennai
    php Training in Chennai

    ReplyDelete
  8. This is a really nice collection. Many thanks for gathering them all together for us. I’ve got a couple in mind for my next project.
    "That’s important information collection."
    mobile app development for android
    !!

    ReplyDelete
  9. It is one of the wonderful blog.you provide a very wonderful information information which is useful to all the viewers to learn android.Thanks for sharing.keep sharing more blogs.

    Android Training in Chennai

    ReplyDelete
  10. really nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge about this. so keep on sharing such kind of an interesting blogs. Android Training in Chennai | Cloud Computing Training in Chennai

    ReplyDelete
  11. Everyone like this blog because you have written that much good content. Look into this Android Online Training Hyderabad for more information.

    ReplyDelete
  12. Your good knowledge and kindness in playing with all the pieces were
    very useful. I don’t know what I would have done if I had not
    encountered such a step like this.
    mobile website builder

    ReplyDelete
  13. You've made some good points there. I looked on the internet for more information about this



    Mainframe Training In Chennai | Hadoop Training In Chennai | ETL Testing Training In Chennai

    ReplyDelete

  14. You've made some good points there. I looked on the internet for more information about this


    Mainframe Training In Chennai | Informatica Training In Chennai | Hadoop Training In Chennai

    ReplyDelete
  15. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    Java Training Institute Bangalore

    Best Java Training Institute Chennai

    ReplyDelete
  16. Ciitnoida provides Core and java training institute in

    noida
    . We have a team of experienced Java professionals who help our students learn Java with the help of Live Base Projects. The object-

    oriented, java training in noida , class-based build

    of Java has made it one of most popular programming languages and the demand of professionals with certification in Advance Java training is at an

    all-time high not just in India but foreign countries too.

    By helping our students understand the fundamentals and Advance concepts of Java, we prepare them for a successful programming career. With over 13

    years of sound experience, we have successfully trained hundreds of students in Noida and have been able to turn ourselves into an institute for best

    Java training in Noida.

    java training institute in noida
    java training in noida
    best java training institute in noida
    java coaching in noida
    java institute in noida

    ReplyDelete
  17. Sap Training Institute in Noida

    CIIT Noida provides Best SAP Training in Noida based on current industry standards that helps attendees to secure placements in their dream jobs at MNCs. CIIT Provides Best ERP SAP Training in Noida. CIIT is one of the most credible ERP SAP training institutes in Noida offering hands on practical knowledge and full job assistance with basic as well as advanced level ERP SAP training courses. At CIIT ERP SAP training in noida is conducted by subject specialist corporate professionals with 7+ years of experience in managing real-time ERP SAP projects. CIIT implements a blend of aERPemic learning and practical sessions to give the student optimum exposure that aids in the transformation of naïve students into thorough professionals that are easily recruited within the industry.

    At CIIT’s well-equipped ERP SAP training center in Noida aspirants learn the skills for ERP SAP Basis, ERP SAP ABAP, ERP SAP APO, ERP SAP Business Intelligence (BI), ERP SAP FICO, ERP SAP HANA, ERP SAP Production Planning, ERP SAP Supply Chain Management, ERP SAP Supplier Relationship Management, ERP SAP Training on real time projects along with ERP SAP placement training. ERP SAP Training in Noida has been designed as per latest industry trends and keeping in mind the advanced ERP SAP course content and syllabus based on the professional requirement of the student; helping them to get placement in Multinational companies and achieve their career goals.

    ReplyDelete


  18. Thanks for sharing such useful information.The content is high quality and results-oriented.Keep sharing more
    Best python certification course in Bangalore

    ReplyDelete
  19. Nice Blog!
    Facing error while using QuickBooks get instant solution with our QuickBooks experts.Dial +1-855-533-6333 QuickBooks Enterprise Support Phone Number Alabama

    ReplyDelete
  20. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..

    Digital Marketing Training in Chennai

    Digital Marketing Course in Chennai


    ReplyDelete
  21. Brilliant post! We are connecting to this extraordinary post on our site. Keep up the extraordinary composition. news updates

    ReplyDelete