I had a requirement to add a web part to default.aspx page from Web part gallery. I have used a Feature to do the same. Please find the code below which is written in “Feature Activated” event.
Get WebPart XML
Hope the code is straightforward to understand.