How to take a screenshot or capture screen programmatically in android

/**
 * @param v view to capture it may be any Layout
 * @return
 */
 public static Bitmap captureScreen(View v)
 {
 Bitmap bitmap = null;

 try {
 if(v!=null)
 {
 int width = v.getWidth();
 int height = v.getHeight();

 Bitmap screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
 v.draw(new Canvas(screenshot));
 }
 } catch (Exception e)
 {
 Log.d("captureScreen", "Failed");
 }

 return bitmap;
 }

Advertisements

Tags: , ,

About krishjlk

http://www.facebook.com/krishna.kanth.121

5 responses to “How to take a screenshot or capture screen programmatically in android”

  1. islealoha says :

    Can someone explain what the line “v.draw(new Canvas(screenshot));” does? Thanks.

    • krishjlk says :

      It will draw the view(v) into bitmap(screenshot) using canvas. What ever the views that are inside view(v) currently will be drawn into a bitmap.

  2. john says :

    i have two images-one is background image and another is a small image on that back image..i am taking the capture of both the image.But after taking the screenshot,the small image is enlarged automatically.So how can i take the screenshot which is same as the images before screenshot??????thnx in advance

  3. dashashok8 says :

    how to take the screenshot of device like, the activity of a anonymous person, just example, i took ur mobile, and i did and open like messages, files and email, what ever operations i did, i want to capture them, how to do these android?

  4. SuperAmine says :

    You are returning a null bitmap.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: