android - take screenshot of entire screen programmatically -


i have code take screenshot of current view, fragment lives activity, activity has background.

private file capturescreen() {      bitmap screenshot = null;     try {          if (view != null) {              screenshot = bitmap.createbitmap(view.getmeasuredwidth(),                     view.getmeasuredheight(), config.argb_8888);             canvas canvas = new canvas(screenshot);             view.draw(canvas);             // save pics             file cache_dir = environment.getexternalstoragedirectory();             bytearrayoutputstream bytes = new bytearrayoutputstream();             screenshot.compress(bitmap.compressformat.png, 90, bytes);             file f = new file(cache_dir + file.separator + "screen.png");             f.createnewfile();             fileoutputstream fo = new fileoutputstream(f);             fo.write(bytes.tobytearray());             fo.close();             return f;         }     } catch (exception e) {         // todo     }     return null; } 

but bitmap saved not i'm expecting. screenshot take fragment elements, not activity background. how can include screenshot?

from :how programmatically take screenshot in android?

// image naming , path  include sd card  appending name choose file string mpath = environment.getexternalstoragedirectory().tostring() + "/" + accuwx.image_append;    // create bitmap screen capture bitmap bitmap; view v1 = mcurrenturlmask.getrootview(); v1.setdrawingcacheenabled(true); bitmap = bitmap.createbitmap(v1.getdrawingcache()); v1.setdrawingcacheenabled(false);  outputstream fout = null; imagefile = new file(mpath);  try {   fout = new fileoutputstream(imagefile);   bitmap.compress(bitmap.compressformat.jpeg, 90, fout);   fout.flush();   fout.close();  } catch (filenotfoundexception e) {    // todo auto-generated catch block    e.printstacktrace(); } catch (ioexception e) {   // todo auto-generated catch block   e.printstacktrace(); } 

try this. work me. , too


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -