title: how to capture the phone screen programmatically in android
body: <p>I want to know how to capture phone screen programmatically. I just googled and got to know that I have to use view.getDrawingCache(). But getDrawingCache() always returns null.</p>
  
  <p>My xml layout is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@+id/screenlayout"&gt;
  &lt;ImageView  
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:id="@+id/screen"
  /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>java file::</p>
  
  <pre><code> public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      View vScreen = findViewById(R.id.screenlayout);
      ImageView imageview = (ImageView)findViewById(R.id.screen);
  
      Bitmap bitmap;
      View v1 = vScreen.getRootView();
      v1.setDrawingCacheEnabled(true);
      bitmap = Bitmap.createBitmap(v1.getDrawingCache());   //getting null here     
      v1.setDrawingCacheEnabled(false)      
      imageview.setImageBitmap(bitmap);
  
  }
  </code></pre>
  
  <p>Can someone please correct me where I am going wrong?</p>