Android Desktop component app widget development in three steps

Source: Internet
Author: User

The Desktop component app widget is a practical function of Android. Although the development process is not very difficult, there are many steps and a little trouble. The following key steps are summarized to facilitate future use. The project is packaged to facilitate future use. Create an android project and follow the steps below to create a simple app widget.

Step 1 create an appwidgetprovider subclass

public class SimpleWidget extends AppWidgetProvider{    @Override    public void onUpdate(Context context,AppWidgetManager appWidgetManager,        int[] appWidgetIds){        super.onUpdate(context, appWidgetManager, appWidgetIds);    }}

Step 2 create the app widget layout file and setting file

Layout file Res/layout/simple_widget.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="TextView" /></LinearLayout>

Set file Res/XML/simple_widget.xml

(Initiallayout must match the layout file name)

<?xml version="1.0" encoding="utf-8"?><appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"     android:initialLayout="@layout/simple_widget"     android:minWidth="72dp"     android:minHeight="72dp"     android:updatePeriodMillis="86400000"     ></appwidget-provider>

Step 3 modify androidmanifest. xml

Add the following subnodes under the application node:

<receiver android:name="SimpleWidget" >    <intent-filter>        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />    </intent-filter>    <meta-data        android:name="android.appwidget.provider"        android:resource="@xml/simple_widget" /></receiver>

Save all. In this step, you can start running. Demo:

Finally, we provide the packaged project source code package ,.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.