Search code examples
androidlauncher

Can't Add AppWidget


I'm compiling ADW source code. (https://github.com/AnderWeb/android_packages_apps_Launcher/archives/b28e9e417c81857cfd2e0265c3c6d409d6c8d0f1)

I wanna add widget more quickly,

so I add a menu item:

menu.add(MENU_GROUP_NORMAL, MENU_ADD_WIDGET, 0, R.string.menu_widget)
            .setIcon(android.R.drawable.ic_menu_compass);

and the relevant action when clicked:

case MENU_ADD_WIDGET:
    showAppWidgetList();
    return true;

the showAppWidgetList() does the same thing as when you click Menu->Add->Widget .

Then I click "my widget item" and the PickWidget dialog shows up,

after clicking a widget,

nothing happens!!!

No widget config or position setting dialog appears.

On the other hand,

if I click Menu->Add->Widget and add a widget,

then Menu->"my widget item" and pick a widget,

then everything works just fine.

How strange!!!

Anybody know what's wrong with it??


Solution

  • It's because Menu->Add->Widget does something before your showAppWidgetList(), you need to do the same thing before showAppWidgetList().

    Analyze the source code, you can find out that the Launcher does the following:

    mAddItemCellInfo = mMenuAddInfo;
    mWaitingForResult = true;
    showAppWidgetList();
    // your method