I am stuck with executing a write command in the code:

            Process sh = Runtime.getRuntime().exec("su -c [command]");
            OutputStream os = sh.getOutputStream();

            String filePath = Environment.getExternalStorageDirectory().getPath();

            Toast.makeText(this, filePath+st+".jpg", Toast.LENGTH_SHORT).show();
            //os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
        //  os.write(("/system/bin/screencap -p " + "\"/data/data/com.example.code/files/"+filePath+".png\"").getBytes("ASCII"));
            os.write(("/system/bin/screencap -p " +filePath+st+".jpg").getBytes("ASCII"));
            os.flush();
            os.close();     
            sh.waitFor();

I have installed SuperUser.apk and placed the "su" binary file in /sdcard/Android/bin folder.

The Toast message itself is not coming up. I guess,

有帮助吗?

解决方案

The answer is that the su is not generated by google. And the emulators wouldn't allow a java code to access the su if its not original. It worked fine with my device though!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top