Android的简单的小工具,启动活动 [英] Android simple widget that launches activity

查看:113
本文介绍了Android的简单的小工具,启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有使用过的部件之前,但我所希望做的是建立一个非常简单的小工具我基本上要进行1:1的小工具,具有只是一个图标,只需设置为背景图像无文字没什么只是一个小图标,当图标为pressed我想打开一个活动。基本上,我想打第二个图标,就像在打开其他活动,而不是主要的一个小窗口形式的应用程序的抽屉。 任何帮助是极大AP preciated

Hi i've never worked with widgets before but what i'm looking to do is create a very simple widget i basically want to make a 1 by 1 widget that has just an icon, just an image set as the background no text nothing just a small icon and when the icon is pressed i want to open an activity. Basically i want to make a second icon like in the app drawer in a widget form that opens another activity rather than the main one. Any help is greatly appreciated

推荐答案

我的供应商最终看上去像这样大量的调查研究后,玩

My provider ended up looking like this after a lot of research and playing

public class WidgetProvider extends AppWidgetProvider {
    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        final int N = appWidgetIds.length;

        for (int i=0; i<N; i++) {
            int appWidgetId = appWidgetIds[i];

            Intent intent = new Intent(context, ClassToLaunchHere.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

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

            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
    }
}

这篇关于Android的简单的小工具,启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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