title: android how to take screen shot programmatically when in surfaceview
body: <p>I don't use xml here and getroot() doesn't work for me. I saw <a href="https://stackoverflow.com/questions/5651442/store-bitmap-screenshot-in-android-cache">Store Bitmap Screenshot in Android Cache</a> but I don't know how he got the mCurrentUrlMask referrence. </p>
  
  <p>my code is:</p>
  
  <pre><code>View v= getRootView();
  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, getMeasuredWidth(), getMeasuredHeight()); 
  
  v.buildDrawingCache(true);
  Bitmap bitmap =v.getDrawingCache();
  path=Environment.getExternalStorageDirectory() + "/test.png";
  File file = new File(path);
  try 
  {
      file.createNewFile();
      FileOutputStream ostream = new                     FileOutputStream(file);
      bitmap.compress(CompressFormat.PNG, 100, ostream);
      ostream.close();
  } 
  catch (Exception e) 
  {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>and I get an ioexception permission deniened while working on the emulator and uses the external-storage permission.(the code works well on a test application while using xml and findviewbyid but in this application I can't use it.</p>