Android 截图程序实现 需要root权限
16lz
2021-01-23
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 |
更多相关文章
- Android -android程序最先加载的Activity
- android 性能分析之常用adb命令adb shell am start -W
- Android查看各分区空间大小命令及相关操作
- Android adb命令选择设备
- 卸载android system/app 目录下文件的应用程序
- Android应用程序键盘(Keyboard)消息处理机制分析(13)
- Hello Android - 去掉窗口标题和程序全屏