让小部件对android系统中的应用 [英] Make widget for an application in android

查看:133
本文介绍了让小部件对android系统中的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在做Android的应用程序。现在我的要求是,我想让此应用的部件。我已经做了小工具示范。但我不知道我怎样才能通过Widget图标启动我的申请。
请给我一个办法做到这一点。
任何帮助将大大AP preciated。

I already made an application in android. Now my requirement is that i want to make a widget for this application. I have already made an Widget Demo. But i don't know how can i launch my application through Widget Icon. Please give me a way to do it. Any help will be greatly appreciated.

推荐答案

主类:

public class Main extends AppWidgetProvider {

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {

    super.onUpdate(context, appWidgetManager, appWidgetIds);
    for  (int i =0 ; i< appWidgetIds.length ; i++)
    {
        int appWidgetId = appWidgetIds[i];

        Intent intent = new Intent();
        intent.setClass(context, Home.class);

        PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
        views.setOnClickPendingIntent(R.id.Site, pending);;

        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

}

AndroidManifest.xml中

AndroidManifest.xml

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

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/widget" />
        </receiver>

Widget.xml:

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" >

<ImageButton
    android:id="@+id/Site"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/app_name"
    android:src="@drawable/commentsms" />

和在res / XML / widget.xml

and in res/xml/widget.xml

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

    </appwidget-provider>

这篇关于让小部件对android系统中的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆