The code you posted would require the phone to be rooted, and probably requires super user privileges. Do you need a screenshot of your application or a screenshot of the phone (even stuff not in your application)? I think taking a screenshot of your application can be done by painting the root view onto a bitmap. I don't know if you can take a screenshot of the phone (outside your application) without super user privileges or some work around (a quick search identified a means using a service the user would have to start from a PC via the Android SDK... but that hardly seems reasonable.)
subject: How do I take screenshot of main screen in android programmatically?