public class Screenshot extends Activity { private static final String DATA_PATH = "/data/data/com.su.ScreenShot/"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); CopyAssets(); Button btClose = (Button) findViewById(R.id.button1); btClose.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { runRootCommand("chmod 777 /data/data/com.su.ScreenShot/gsnap"); Log.v("2", "2---------------"); runRootCommand("/data/data/com.su.ScreenShot/gsnap test.jpg /dev/graphics/fb0");//使用有root权限的命令 运行gsnap的c程序 Log.v("3", "3---------------"); } }); } public static boolean runRootCommand(String command) { Process process = null; DataOutputStream os = null; try { process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command + "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { return false; } finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { // nothing } } return true; } public static boolean runCommand(String command) { Process process = null; try { process = Runtime.getRuntime().exec(command); process.waitFor(); } catch (Exception e) { return false; } finally { try { process.destroy(); } catch (Exception e) { // nothing } } return true; } private void CopyAssets() { AssetManager assetManager = getAssets(); String[] files = null; try { files = assetManager.list(""); } catch (IOException e) { } for (int i = 0; i < files.length; i++) { InputStream in = null; OutputStream out = null; try { if (!(new File(DATA_PATH + files[i])).exists()) { in = assetManager.open(files[i]); out = new FileOutputStream(DATA_PATH + files[i]); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } } catch (Exception e) { } } } private void copyFile(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } } } 其实主要还是人家的c程序 我只是写了几句shell命令
赚点豆豆~
http://down.51cto.com/data/338583