简体   繁体   English

如何以编程方式在主屏幕上显示小部件

[英]How to bring up a widget on home screen programatically

Programmatically I'm 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) .以编程方式,我试图在主屏幕上显示一个小部件,但在通过意图传递小部件 ID 并调用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);
}

I am getting extras= null here.我在这里得到了extras= null So, I tried allocating widget ID as WidgetId = mAppwidgetHost.allocateAppWidgetId();因此,我尝试将小部件 ID 分配为WidgetId = mAppwidgetHost.allocateAppWidgetId();

Sent through the intent:通过意图发送:

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 please 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.您不能这样做:标准的小部件选择器不允许您指定特定的小部件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM