冷不丁的就要用到代码输入adb 命令行,这里做个简单记录
修改文件权限
try {
/* Missing read/write permission, trying to chmod the file */
Process su;
su = Runtime.getRuntime().exec("/system/bin/su");
String cmd = "chmod 777 " + device.getAbsolutePath() + "\n"
+ "exit\n";
su.getOutputStream().write(cmd.getBytes());
if ((su.waitFor() != 0) || !device.canRead()
|| !device.canWrite()) {
throw new SecurityException();
}
} catch (Exception e) {
e.printStackTrace();
throw new SecurityException();
}
获取mac地址
/**
* 通过命令行获取平板的MAC值
*/
private String catMac() {
String mac = "";
try {
Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line;
while ((line = input.readLine()) != null) {
mac += line.trim();
}
input.close();
} catch (IOException e) {
e.printStackTrace();
}
return mac;
}