سؤال

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