Screenshot of the whole device screen Android from service -


i'm trying take screenshot background accessibility service of whole screen, tried insert view service drawn on current application , try using that.but view black background. appreciated, thank :d

public void addview() {     windowmanager windowmanager = (windowmanager) getsystemservice(window_service);     layoutinflater inflater = (layoutinflater) getsystemservice(layout_inflater_service);       if (layout != null) {         windowmanager.removeviewimmediate(layout);      } else {         layout = (relativelayout) inflater.inflate(r.layout.hoock_layout, null);         layout.setdrawingcacheenabled(true);     }      windowmanager.layoutparams params = new windowmanager.layoutparams(windowmanager.layoutparams.wrap_content, windowmanager.layoutparams.wrap_content, windowmanager.layoutparams.type_system_alert, windowmanager.layoutparams.flag_not_focusable | windowmanager.layoutparams.flag_not_touch_modal, pixelformat.translucent);     params.gravity = gravity.left | gravity.top;     params.x = 0;     params.y = 0;     windowmanager.addview(layout, params);      store(getscreenshot(layout), "test.png"); } 

public bitmap getscreenshot(view view) {

    view screenview = view.getrootview();     screenview.setdrawingcacheenabled(true);       screenview.measure(view.measurespec.makemeasurespec(1500, view.measurespec.unspecified),             view.measurespec.makemeasurespec(1800, view.measurespec.unspecified));     screenview.layout(0, 0, screenview.getmeasuredwidth(), screenview.getmeasuredheight());      screenview.builddrawingcache(true);     screenview.setdrawingcacheenabled(true);     bitmap bitmap = bitmap.createbitmap(screenview.getdrawingcache());     return bitmap; }   public void store(bitmap bm, string filename) {     final string dirpath = environment.getexternalstoragedirectory().getabsolutepath() + "/accessibilitypof";     file dir = new file(dirpath);     if (!dir.exists())         dir.mkdirs();     file file = new file(dirpath, filename);     try {           fileoutputstream fout = new fileoutputstream(file);         bm.compress(bitmap.compressformat.png, 85, fout);         fout.flush();         fout.close();     } catch (exception e) {         e.printstacktrace();     } } 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -