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. Python操作MySql --Python3

    Python版本:v3.7 模块:pymysql 1.连接数据库 connectDB.py: # coding:utf-8import pymysql host = 'localhost' # 主机u ...

  2. ionic3 打包一个已签名的apk

    1 进入ionic官方文档,点击左边导航菜单,找到INTRO下的Deploying2 终端进入项目目录(根据项目环境定是否需要root权限)3 运行命令ionic cordova build andr ...

  3. Lab 1-2

    Analyze the file Lab01-02.exe. Questions and Short Answers Upload the Lab01-02.exe file to http://ww ...

  4. You Don't Know JS: Async & Performance(第2章,Callbacks)

    Chapter 2: Callbacks. Callbacks are by far the most common way that asynchrony in JS programs is exp ...

  5. p1217 Prime Palindromes

    1.回文质数的数量很少 2.除了11以外的回文质数都是偶数. 3.1-1亿内的回文数不到30000个. 4.1-10000的质数约1000个. 这样深搜找出所有的回文数,再判断是否质数. #inclu ...

  6. hdu-6194 string string string 后缀数组 出现恰好K次的串的数量

    最少出现K次我们可以用Height数组的lcp来得出,而恰好出现K次,我们只要除去最少出现K+1次的lcp即可. #include <cstdio> #include <cstrin ...

  7. Flutter学习之路---------第一个Flutter项目

    Flutter是谷歌的移动UI框架,可以快速在iOS和Android上构建高质量的原生用户界面. Flutter可以与现有的代码一起工作.在全世界,Flutter正在被越来越多的开发者和组织使用,并且 ...

  8. 走起 ~私有gitlab

    1.创建gitlab 账号,创建一个项目名称  地址:http://git.limikeji.com 2.配置git环境 用git命令上传代码 3.配置gitlab ssh 4.使用git命令上传代码 ...

  9. 141. Linked List Cycle&142. Linked List Cycle II(剑指Offer-链表中环的入口节点)

    题目: 141.Given a linked list, determine if it has a cycle in it. 142.Given a linked list, return the ...

  10. python记录_day31 进程同步和进程通信

    一.进程同步 1.同步锁(又叫互斥锁) 加锁的代码以后,同一时间内只能被一个进程执行 from multiprocessing import Process, Lock def fun(loc): l ...