如何打开主屏幕上一个小部件编程 [英] How to bring up a widget on home screen programatically

查看:148
本文介绍了如何打开主屏幕上一个小部件编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过编程,我试图把一个插件的主屏幕上,但我面对的问题,而通过小部件ID通过意图和放大器;调用startActivity(pickIntent)。 窗口小部件列表快到了,但小部件,我已经开发是没有得到选择。

Programatically i am trying to bring a widget on the home screen but i am facing problem while passing the widget ID through an intent & calling startActivity(pickIntent). The widget list is coming up but widget which i have developed is not getting selected.

final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(component);
Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null) {
            mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
}

我收到额外= NULL在这里。

I am getting "extras= null" here.

所以,我想分配部件编号: 为widgetid = mAppwidgetHost.allocateAppWidgetId();

So i tried allocating widget ID: WidgetId = mAppwidgetHost.allocateAppWidgetId();

通过意图发送:

Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
        pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, WidgetId);
        startActivity(pickIntent);

不过还是我的小工具是没有得到选择。 任何人都可以请让我知道我该如何调出主屏幕上一个小部件,无需任何用户交互。 在此先感谢...

but still my widget is not getting selected. Can anyone pls let me know how do i bring up a widget on home screen, without any user interaction. Thanks in advance...

推荐答案

您不能做到这一点:标准的部件选择器不允许你指定一个特定的窗口小部件

You can't do this: the standard widget picker does not allow you to specify a specific widget.

这篇关于如何打开主屏幕上一个小部件编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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