0

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,

  • Please, do yourself a favour and learn how to use the debugger. Toast is not a great way of debugging apps. You have not provided anywhere near enough information. If the Toast is not displaying, then either this fragment of code is never executed or you have a crash. Which one? – Simon Jul 13 '13 at 08:49
  • The code is getting called.. But, if there is a Toast before the exec, it shows up, but not after.. – Hariprasauth Ramamoorthy Jul 13 '13 at 08:52

1 Answers1

0

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!