Can I take a screenshot on the home screen programmatically without cropping my Android device?

I want to take a screenshot of my home screen. How can i achieve this? I can take screenshots of the current activity, but not on the main screen.

My codes for taking screenshots of current activity

View v1 = linearlayout_var.getRootView(); v1.setDrawingCacheEnabled(true); Bitmap bm = v1.getDrawingCache(); BitmapDrawable bitmapDrawable = new BitmapDrawable(bm); imageview.setBackgroundDrawable(bitmapDrawable); 

If I want to take a screenshot on the main screen, then I should use linearlayout_var instead, so that I can get to the root representation of the home screen.

In one line, my question is: how to get the root view of the Homescreen?

+7
android screenshot
source share
1 answer

Try this one

 getWindow().getDecorView().findViewById(android.R.id.content); 

Hope this helps.

-one
source share

All Articles