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

C程序的地址http://download.csdn.net/detail/sfshine/3781315

更多相关文章

  1. Android -android程序最先加载的Activity
  2. android 性能分析之常用adb命令adb shell am start -W
  3. Android查看各分区空间大小命令及相关操作
  4. Android adb命令选择设备
  5. 卸载android system/app 目录下文件的应用程序
  6. Android应用程序键盘(Keyboard)消息处理机制分析(13)
  7. Hello Android - 去掉窗口标题和程序全屏

随机推荐

  1. Android 单选框RadioGroup
  2. [置顶] Android内核和驱动篇-Android内核
  3. AndroidStudio 报 Error:Execution faile
  4. Android studio 中NDK的配置和JNI实现的
  5. Android 原生获取地理位置
  6. Android多媒体开发(5)————利用Android
  7. 联发科智能机战略转投Android 加速其规范
  8. android之单选框
  9. 1、What Makes an Android Application?
  10. 谁说Android的动画不廉价(二)之转场动画