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.

36 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. Nice post.Give it up. Thanks for share this article. For more visit:android 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. I agree with your post. Android software development kit makes the application development process lot simpler and effective. You can create best performing android application with ease. Android Training Institutes in Chennai | Best Android Training in Chennai

    ReplyDelete
  7. 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
  8. 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
  9. 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..

    Mobile App Development Company in Chennai
    Android app Development Company in Chennai
    ios app development Company in Chennai

    ReplyDelete
  10. 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
  11. Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..
    Android App Development Company

    ReplyDelete
  12. Thanks for posting useful information.You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...Really it was an awesome article...very interesting to read..
    please sharing like this information......
    Android training in chennai
    Ios training in chennai

    ReplyDelete
  13. I just want to say that all the information you have given here is awesome...great and nice blog thanks sharing..Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    Web Design Development Company
    Web design Company in Chennai
    Web development Company in Chennai

    ReplyDelete
  14. it is really amazing...thanks for sharing....provide more useful information...
    Mobile app development company

    ReplyDelete
  15. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  16. 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
  17. 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
  18. Everyone like this blog because you have written that much good content. Look into this Android Online Training Hyderabad for more information.

    ReplyDelete
  19. 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

  20. 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
  21. 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

  22. 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
  23. 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
  24. 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
  25. 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
  26. The information which you have provided is very good. It is very useful who is looking for selenium Online Course Bangalore

    ReplyDelete
  27. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us. Do check Six Sigma Training in Bangalore | Six Sigma Training in Dubai & Get trained by an expert who will enrich you with the latest trends.

    ReplyDelete