java - Not able to take screenshot in Android L programmatically -


i'm using nexus 5. version 5.1.1

i want take screenshot programmatically of phone @ given time. i'm okay if solution specific nexus 5.

after reading many answers, i've tried below solution using screencap.

issue creates image file, blank.

private void takess() {     try {          if (isexternalstoragewritable()) {              process su = runtime.getruntime().exec("/system/bin/screencap -p /storage/emulated/0/img.png\n");             dataoutputstream outputstream = new dataoutputstream(su.getoutputstream());              outputstream.flush();             su.waitfor();              bufferedreader bufferedreader = new bufferedreader(new inputstreamreader(su.getinputstream()));              string line;             while ((line = bufferedreader.readline()) != null) {                 string output = line + system.getproperty("line.separator");                 system.out.println(line);             }         }     } catch (exception e) {         e.printstacktrace();     } }  /* checks if external storage available read , write */ public boolean isexternalstoragewritable() {     string state = environment.getexternalstoragestate();     if (environment.media_mounted.equals(state)) {         return true;     }     return false; } 

the same command if run command prompt, executes successfully. please suggest might issue.

p.s. - phone rooted.

thank you

have tried executing command su?

"/system/bin/su -c \"/system/bin/screencap -p /storage/emulated/0/img.png\""


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -