ADB 无线调试命令
son =
"setprop service.adb.tcp.port 5555\n" +
"stop adbd\n" +
"start adbd\n";
soff = "setprop service.adb.tcp.port -1\n" +
"stop adbd\n" +
"start adbd\n";
reboot 立即重启

//获取Ip 
String getIp() {
String ip = "127.0.0.1";
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
if (!wm.isWifiEnabled()) {
wm.setWifiEnabled(true);
}
WifiInfo wi = wm.getConnectionInfo();
int addr = wi.getIpAddress();
return intToIp(addr);
} String intToIp(int t) {
return (t & 0xFF) + "." + ((t >> 8) & 0xFF) + "." + ((t >> 16) & 0xFF) + "." + ((t >> 24) & 0xFF);
} //执行普通命令
String exec(String cmd) {
if (cmd.startsWith("su")|cmd.startsWith("ping")) {
return "不允许执行的命令";
}
String result = "";
Process ps = null; ProcessBuilder pb = new ProcessBuilder(cmd);
InputStream es = null;
InputStream is = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int read = -1;
ps = pb.start();
es = ps.getErrorStream();
while ((read = es.read()) != -1) {
baos.write(read); }
baos.write('\n');
is = ps.getInputStream();
while ((read = is.read()) != -1) {
baos.write(read); }
byte[] data = baos.toByteArray();
result = new String(data);
} catch (IOException e) {
e.printStackTrace();
} finally {
try { if (es != null) {
es.close();
} if (is != null) {
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
if (ps != null) {
ps.destroy();
}
}
return result;
}
//执行root命令
String rootExec(String cmd) {
if (cmd.startsWith("su")|cmd.startsWith("ping")) {
return "不允许执行的命令";
}
String result = "";
DataOutputStream dos = null;
DataInputStream dis = null;
try {
Process ps = Runtime.getRuntime().exec("su");
dos = new DataOutputStream(ps.getOutputStream());
dis = new DataInputStream(ps.getInputStream());
dos.writeBytes(cmd + "\n");
dos.flush();
dos.writeBytes("exit\n");
dos.flush();
String line = null;
while ((line = dis.readLine())!=null) {
result += "\n"+line;
// Message ms = new Message();
// ms.obj = line;
// handler.sendMessageDelayed(ms,1000);
} ps.waitFor();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (dos != null) { try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (dis != null) { try {
dis.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
return result;
}

android 应用程序中执行Linux 命令的更多相关文章

  1. 在Python程序中执行linux命令

    import commands print commands.getstatusoutput('ls') 输出: (0, '1.py\nwork.nfs') 参考文档: https://blog.cs ...

  2. 使用Android平板编程,执行linux命令

    android有一些应用支持开发, AIDE 介绍http://www.wandoujia.com/apps/com.aide.ui https://play.google.com/store/app ...

  3. 在程序中执行shell命令

    在linux系统下的操作中我们会经常用到shell命令来进行,一开始学习进程的时候对于shell命令也进行了思考,认为shell命令就是一个进程的外壳,经过了后来的学习对于这一点也有了更多的认识. 用 ...

  4. 如何在java程序中调用linux命令或者shell脚本

    转自:http://blog.sina.com.cn/s/blog_6433391301019bpn.html 在java程序中如何调用linux的命令?如何调用shell脚本呢? 这里不得不提到ja ...

  5. 写一段java程序来执行linux命令

    摘要 在日常开发中,程序员需要经常查询服务器日志来排查问题和调试程序.如果是本地调试还好,但项目一旦发布到服务器上,每次查日志就很麻烦,而且日志量巨大,有时我们无法找到我们需要的信息.经常需要借助第三 ...

  6. 在c++程序中执行DOS命令

    转自博客:http://blog.csdn.net/ypist/article/details/8485049 #1,system()方式 在C盘根目录下新建文件夹,名称为12: system(&qu ...

  7. Java代码中执行Linux命令,亲测可用

    前提需要知道怎么在linux怎么新建java文件和怎么编译,否则请先学其他知识!! import java.io.*;public class Test{ public static void mai ...

  8. perl中执行linux命令,及其区别

    1. system("date '+%Y-%m-%d %H:%M:%S'") 该命令返回的是-1.(应该是date命令的main函数的返回值) 2. `date '+%Y-%m-% ...

  9. java程序中调用Linux命令Windows命令

    目前总结的方法: 调用Linux简单的命令行,设置文件夹权限755 String scriptDir = "/home/wenf"; String cmd = "chmo ...

随机推荐

  1. WebStrom配置

    1.下载安装Node.jshttps://nodejs.org/en/download/2.配置node路径3.修改文件默认字符集

  2. python2.x编码问题实例

    1,编码问题,主要是区分面向人类的字符串,面向计算机的字节序列 在python3中,字符串是str(默认即unicode),字节序列是bytes 在python2中,字符串是unicode,字节序列是 ...

  3. vue 基础(一)

    一 vue.js的M-V-VM思想 MVVM 是Model-View-ViewModel 的缩写,它是一种基于前端开发的架构模式. 1.Model指代的就是vue对象的data属性里面的数据.这里的数 ...

  4. 关于StringUtils的常用方法

    StringUtils.split(String, char) * <pre> * StringUtils.split(null, *) = null * StringUtils.spli ...

  5. 6月5 Smarty变量调节器

    变量调节器:<{$a|变量调节器}> 主要修改此页面的信息来了解变量调节器:test0605/main.php和模板文件:main0605.html 1.利用给定的变量调节器 capita ...

  6. poj-2514-模拟

    http://poj.org/problem?id=2514 Ridiculous Addition Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  7. 从零搭建和配置OSX开发环境

    对于每一名开发者来说,更换系统或者更换电脑的时候,都免不了花上不短的时间去折腾开 发环境的问题.我本人也是三番两次,深知这个过程的繁琐.所有,根据我自己以往的经验, 以及参考一下他人的意见,整理一下关 ...

  8. 利用sqlldr从MySQL导出一张表数据到Oracle

    根据业务需求,需要从MySQL库中同步一张表tap_application到Oracle中,下面是记录的导入过程. 1. 查看MySQL表结构 desc tap_application; +----- ...

  9. 基本数据类型dict

    1. 字典 dict 用{}来表示 键值对数据 {key:value} 唯一性 键 都必须是可哈希的 不可变的数据类型就可以当做字典中的键 可哈希不可变的数据类型:int str tuple bool ...

  10. [CodeForces - 447B] B - DZY Loves Strings

    B - DZY Loves Strings DZY loves collecting special strings which only contain lowercase letters. For ...