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.
Search logcat for somethig like that
perrmission failure: android.permission.READ_FRAME_BUFFER from uid=10113 pid=2934 113 PermissionCache D checking android.permission.READ_FRAME_BUFFER for uid=10113 => denied (294 us) 113 SurfaceFlinger E Permission Denial: can't read framebuffer pid=2934, uid=10113
If you get that error that means permission problem.
Even if you add the READ_FRAME_BUFFER permissions it still wouldn't work. Generally, That means the application doesn't have permissions to read the framebuffer and must be compiled with system certificate or use su to get root privileges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With