/** * Get current screen and save */private void Getandsavecurrentimage () {//1. Build bitmap WindowManager WI Ndowmanager = Getwindowmanager (); Display display = Windowmanager.getdefaultdisplay (); int w = display.getwidth (); int h = display.getheight (); Bitmap Bmp = Bitmap.createbitmap (W, H, config.argb_8888); 2. Get the screen View Decorview = This.getwindow (). Getdecorview (); Decorview.setdrawingcacheenabled (TRUE); BMP = Decorview.getdrawingcache (); String Savepath = Getsdcardpath () + "/andydemo/screenimage"; 3. Save Bitmap try {file path = new File (Savepath); File String filepath = savepath + "/screen_1.png"; File File = new file (filepath); if (!path.exists ()) {path.mkdirs (); } if (!file.exists ()) {file.createnewfile (); } FILEOUTPUtstream fos = null; FOS = new FileOutputStream (file); if (null! = FOS) {bmp.compress (Bitmap.CompressFormat.PNG, N, FOS); Fos.flush (); Fos.close (); Toast.maketext (circleshareactivity.this, "screenshot file saved to sdcard/andydemo/screenimage/", Toast.length_long). Show (); }} catch (Exception e) {e.printstacktrace (); }}/** * get SDcard folder path function * @return */private String Getsdcardpath () {File Sdcarddir = n Ull Infers whether SDcard exists as a Boolean sdcardexist = Environment.getexternalstoragestate (). Equals (Android.os.Environment.MEDIA_MOU NTED); if (sdcardexist) {sdcarddir = Environment.getexternalstoragedirectory (); } return sdcarddir.tostring (); }
Android gets and saves it to the local SD on the card path