Search code examples
androidscreenshotrootframebuffersu

Why program still don't take screenshot after getting "su"?


I push the button and program get SU, but png file is 0 bytes weight. Logcat says

Permission denied: can't read framebuffer pid=12844 uid=10087.

So why that's so. My phone is rooted, program already get su. What's wrong?

Button btn = (Button) findViewById(R.id.button1);
        btn.setOnClickListener (new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                try {
                    Process process = Runtime.getRuntime().exec("su");
                    Process pr = Runtime.getRuntime().exec("/system/bin/screencap -p /sdcard/s.png");
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });

Solution

  • You should use this one, it should have better support:

    @Override
    public void onCLick(View v)
     try{
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
    
        os.writeBytes("/system/bin/screencap -p /sdcard/s.png\n");
        os.writeBytes("exit\n");
        os.flush();
        os.close();
    
        process.waitFor();
     } catch (Exception e){
     };
    };