My initial goal is to add the Google Search widget to the linear layout of the activity. I need to include it just like it appears and works in the Launcher (this is why I need to be able to add the widget).


I would like to add widgets to my activity whithout having to launch the widget picker activity. I tried to:

1. directly specify an integer id (I always get inflate errors)

2. get the id like this:

  ComponentName cn = new ComponentName(getBaseContext(), "com.android.quicksearchbox.SearchWidgetProvider");
  int[] ids = AppWidgetManager.getInstance(getApplicationContext()).getAppWidgetIds (cn);

(the array is always empty)

None of these works.

After this I have this code, to use the ID (it works if I get the ID from the widget picker activity):

    AppWidgetProviderInfo withWidgetInfo = AppWidgetManager.getInstance(getApplicationContext()).getAppWidgetInfo(appWidgetId);
    AppWidgetHostView hostView = myWidgetHost.createView(getBaseContext(), appWidgetId, withWidgetInfo);
    hostView.setAppWidget(appWidgetId, withWidgetInfo);
    LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
    ll.addView(hostView);

How should I do it? Thank you!

Edit
Report