4

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_APPWIDGET_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.

Mangesh
  • 5,491
  • 5
  • 48
  • 71
schumi
  • 41
  • 2

1 Answers1

4

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

Femi
  • 64,273
  • 8
  • 118
  • 148
  • Can you pls let me know is there anyway to simulate the user interaction of selecting the particular widget from the list? – schumi Jul 12 '11 at 05:50
  • At this time there is no way to simulate that user interaction: I'd spent a painful day searching for an answer to that very question. It would be a nice user interface improvement (one button widget installation) but unfortunately the activity that is launched when you send the Intent (at http://android.git.kernel.org/?p=platform/packages/apps/Settings.git;a=blob;f=src/com/android/settings/AppWidgetPickActivity.java;h=176ac80c38553eab3d18c3f3197188f59ca0ada1;hb=7be5137e12ba58cebae634f640379599acdb491a) does not provide a way to actually force it to pick a specific Widget. – Femi Jul 12 '11 at 06:01
  • 1
    how does the app CM flashlite does this, it asds homescreen widget during the installation itself during – user2548816 Aug 21 '16 at 16:04
  • user2548816 did you find a solution to replicate CM Flashlite? – nivensookharan Jan 22 '17 at 04:16