androidandroid-widgetandroid-firmware

How to define which widget shall be placed on homescreen and at which position after factory reset?


Assuming I have my apk signed with the platform key and as part of the system:

My app has a widget, which I would like to place on the (system's default - Galaxy Tab P7500, Android 3.2) home screen right after starting the device fresh from factory reset - the same way as the Google Search widget is already there after you're doing a factory reset.

My question is: where exactly is it defined, which widget should be placed onto the home screen and at which position at factory reset time?


Solution

  • Look at AppWidgetService and /data/system/appwidgets.xml. It matches widget providers (apps) with widget hosts (launchers, etc.). Where exactly the widget appears is controlled by the launcher itself using the appWidgetId for reference. For the default launcher (on ICS), this is kept in the launcher.db database.

    So if you add it to appwidgets.xml and give it an ID, then insert the proper row in the database, it should show up on the homescreen.