开发者

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). 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_APPWIDG开发者_Go百科ET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
}

I am getting extras= null here. So, I tried allocating widget ID as 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜