0

I want to take snapshot of my device screen's snapshot on Button click. Please provide some code sample instead of links.

Thanks in advance.

Deepika Lalra
  • 1,035
  • 1
  • 10
  • 24

2 Answers2

4

I got the answer for my question. Actualy i am getting bitmap as null. but i found the reason and the solution.

View v = findViewById(R.id.attachments_list);
    v.setDrawingCacheEnabled(true);
    // this is the important code :)
    // Without it the view will have a dimension of 0,0 and the bitmap will
    // be null
    v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());

    v.buildDrawingCache(true);
    Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache());
Deepika Lalra
  • 1,035
  • 1
  • 10
  • 24
  • no not yet. Actually i read somewhere that every site has its own mechanism to provide thumbnails like youtube provided. but there is not an hard and fast rule to get thumb for video Url. Another thing is we can make thumbnail for a video which is saved in phone or dowloaded but for streaming videos there is no specific way. – Deepika Lalra Nov 02 '12 at 12:55
  • http://api.embed.ly/1/oembed?url=PASTE YOUR URL&maxwidth=500 – Deepika Lalra Nov 22 '12 at 04:44
  • @venkat you make a function which can call this url and get the json an parse that json and you can get all information about that video. I did using this url and this works like a charm. – Deepika Lalra Nov 23 '12 at 11:47
  • @Venkat do not append http:// with url. try using www. as a prefix for your URl. it will work already tested by me. – Deepika Lalra Dec 19 '12 at 08:12
  • thank you... after remove http://from the url its working fine... – Venkat Dec 22 '12 at 07:00
  • @DeepikaLalra but i want take the screen shot of another activity .. – Rishi Gautam Aug 20 '13 at 06:32
1

You can't take your Device's screenshot(not rooted) but within your application you can.

Below is the code which takes screenshot of your application's screen and save a file in your sdcard.

mLayoutRoot.setDrawingCacheEnabled(true); //mLayoutRoot is your Parent Layout(may be RelativeLayout, LinearLayout or etc..)
mLayoutRoot.buildDrawingCache();

Bitmap mBitmap= mLayoutRoot.getDrawingCache();
try {
    if(mBitmap!=null)
    {
        FileOutputStream out = new FileOutputStream("/sdcard/filename.png"));
        mBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
        out.flush();
        out.close();
    }
} catch (Exception e) {}            
Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115