I'm having trouble with capturing the screen of un-rooted phone.
I've tried the command at my computer:
adb shell /system/bin/screencap -p /sdcard/out.png
and this worked well.
However, whenever I try to use this command at my application like this :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] str ={"/system/bin/screencap","-p","/sdcard/out.png"};
try {
Process ps = Runtime.getRuntime().exec(str);
try {
ps.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
Toast.makeText(this, ""+e, Toast.LENGTH_LONG).show(); }
}
I always get 0 byte of out.png. I think there is no error on the source code, but I can't understand why this kind of error occurs.
Please help me with this problem.
Thanks.