开发环境AS4.0,kotlin1.72,java8
为了开发调试方便
我们经常需要网络调试
蛋疼的是
每次关机又要重新打开网络调试
很麻烦,而且容易被累死
所以我开发了这
另外,此APP需要root权限
如果失败,那就老老实实插上USB连接电脑adb
运行:“adb tcpip 5555”
1.把MainActivity做成了1像素,而且透明。打开网络调试后就关掉,这样用户就无感
2.桌面APP图标长按弹出对话框,进行端口设置
/**
* 打开网络调试
* @return 是否成功
*/
fun openNetworkDebugging(): Boolean {
var os: DataOutputStream? = null
return try {
val process = Runtime.getRuntime().exec("su")
os = DataOutputStream(process.outputStream)
os.writeBytes("setprop service.adb.tcp.port $PORT\n")
os.writeBytes("start adbd\n")
os.flush()
true
} catch (e: Exception) {
false
} finally {
try {
os?.close()
} catch (e: IOException) {
}
}
}
/**
* 关闭网络调试
* @return 是否成功
*/
fun closeNetworkDebugging(): Boolean {
var os: DataOutputStream? = null
return try {
val process = Runtime.getRuntime().exec("su")
os = DataOutputStream(process.outputStream)
os.writeBytes("setprop service.adb.tcp.port 5555\n")
os.writeBytes("stop adbd\n")
os.flush()
true
} catch (e: Exception) {
false
} finally {
try {
os?.close()
} catch (e: IOException) {
}
}
}
本文地址:https://blog.csdn.net/Yu1441/article/details/107182773
如对本文有疑问, 点击进行留言回复!!
SpringBoot引用阿里easyexcel,Excel导出返回浏览器下载
HashMap、Hashtable、ConcurrentHashMap三者间的异同
解决RecycleView 中Item包含Edittext时,滑动view复用导致数据错乱的问题
多线程、同步工作原理、死锁案例、Lock接口、线程的生命周期的讲解及实现
网友评论