Number 4-17 in the 360 cloud disk provides the download of the Art of War app, as a beta version, in just 10 days to download more than 1000, although not very high, but also proves that my one months of effort is worth it.
This two days game updated, I will also launch the latest version, on the basis of the original test version, modified some of the contents of the error, the optimization of some of the interface, the introduction of the life of the generals, generals, such as the growth value of information.
Because the vast number of users put forward equipment simulation can not be saved after the problem, I learned on the basis of the solution, but helpless did not solve the success, and then first use the function to achieve the properties of the simulation after the storage bar.
Baidu on the Internet a lot, most of it is quite complex, for my level, is still unable to digest, looking for a few days, and finally found a simple way to achieve.
is actually a function, this function implements the function
1 /**2 * Gets and saves the current screen's3 */4 Private voidgetandsavecurrentimage ()5 { 6 //Build Bitmap7WindowManager WindowManager =Getwindowmanager (); 8Display display =Windowmanager.getdefaultdisplay (); 9 intW =display.getwidth (); Ten inth =display.getheight (); OneBitmap BMP =Bitmap.createbitmap (W, H, config.argb_8888); A //Get Screen -View Decorview = This. GetWindow (). Getdecorview (); -Decorview.setdrawingcacheenabled (true); theBMP =Decorview.getdrawingcache (); - //Picture Storage Path -String Savepath = Getsdcardpath () +"/qxbf/screenimages"; Here is the saved path - //Save Bitmap + Try { -File Path =NewFile (Savepath); +Time time =NewTime ("gmt+8"); The current time of the mobile system is found here, which is used to name the truncated image. Otherwise the same name, will only produce a picture, want to produce more than one picture, you need each picture's name is different, I use the most water method, with the system time to name A Time.settonow (); at intYear =time.year; - intmonth =Time.month; - intDay =Time.monthday; - intminute =Time.minute; - inthour =Time.hour; - intSEC =Time.second; in //file -String filepath = savepath+"/"+ year+month+day+minute+sec+". PNG"; This gives the picture a name toFile File =NewFile (filepath); + if(!path.exists ()) {//Determine if path exists - Path.mkdirs (); the } * if(!file.exists ()) { $ File.createnewfile (); Panax Notoginseng } -FileOutputStream fos =NULL; theFOS =Newfileoutputstream (file); + if(NULL!=Fos) { ABmp.compress (Bitmap.CompressFormat.PNG, -, FOS); the Fos.flush (); + Fos.close (); -Toast.maketext (Equip_pk_result. This,"screenshot file saved to the sdcard/qxbf/screenimages/directory", Toast.length_long). Show (); $ } $}Catch(Exception e) { - E.printstacktrace (); - } the } - /**Wuyi * Get the directory path function of SDcard the * @return - */ Wu PrivateString Getsdcardpath () { -File Sdcarddir =NULL; About //determine if sdcard exists $Boolean sdcardexist =environment.getexternalstoragestate (). Equals (Android.os.Environment.MEDIA_MOUNTED); - if(sdcardexist) { -Sdcarddir =environment.getexternalstoragedirectory (); - } A returnsdcarddir.tostring (); +
You also need to add a system permission that corresponds to the function
Under the Androidmanifest.xml file
1 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The specific use is to click a button, in the response of the button to call this function in the event.
Android Development _ Implementation function