android - Screenshot to any screen with button on top -


i have button on top, allows me explore android ui, , i'm trying add screenshot action , , part of adding action button works fine, doesn't work screenshot code, code works when add code "myactivity" button, when i'm exploring android ui, , when action on allways on top button, gives me black image no data (0 kb). screenshot code:

view content = findviewbyid(android.r.id.content).getrootview(); content.setdrawingcacheenabled(true);    bitmap bitmap = content.getdrawingcache();    file file = new file( environment.getexternalstoragedirectory() + "/test.png");    try     {        file.createnewfile();        fileoutputstream ostream = new fileoutputstream(file);        bitmap.compress(compressformat.png, 100, ostream);        ostream.close();    }     catch (exception e)     {        e.printstacktrace();    } 

maybe problem contentor maybe can't done without root access, if root access needed, can give me sample code?

here code taking screen shot via shell command on rooted device 'filedestination' path location @ want screenshot file saved.

    try {         process process = runtime.getruntime().exec("su", null,null);          outputstream os = process.getoutputstream();         os.write(("/system/bin/screencap -p " + filedestination).getbytes("ascii"));         os.flush();         os.close();         process.waitfor();     } catch (ioexception e) {         log.d(tag,log_label+" ioexception e:: screenshot failed");         e.printstacktrace();     } catch (interruptedexception e) {         log.d(tag,log_label+"interruptedexception e:: screenshot failed");         e.printstacktrace();     } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -