android 使用linux命令截屏

public static void screenShot(){
        try {
            Process sh = Runtime.getRuntime().exec("sh");
            //Process sh = Runtime.getRuntime().exec("su");
            DataOutputStream  os = new DataOutputStream(sh.getOutputStream());
            os.writeBytes(("screencap -p /sdcard/screenshot.png"));
            os.flush();
            os.close();
            sh.waitFor();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

exec("su")不行的话就exec("sh"),因为这条命令是需要在root进程中使用

猜你喜欢

转载自blog.csdn.net/always_and_forever_/article/details/81974820