这篇文章给大家介绍adb forWord通信怎么在Android移动端与PC端中使用,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。PC端与Android手机端使用adb forword通信服务器端代码如下:import
这篇文章给大家介绍adb forWord通信怎么在Android移动端与PC端中使用,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
PC端与Android手机端使用adb forword通信
服务器端代码如下:
import java.io.IOException; import java.io.ObjectOutputStream; import java.net.Socket; import java.net.UnknownHostException; import java.util.Scanner; public class Server { public static final String TAG = "server"; public static int PC_LOCAL_PORT = 22222; public static int PHONE_PORT = 22222; public static String ADB_PATH = "adb.exe"; public static void main(String[] args) { // TODO Auto-generated method stub YingyonghuiHubServer.execAdb(); } public static void execAdb() { // run the adb bridge try { Process p = Runtime.getRuntime().exec( ADB_PATH + " forward tcp:" + PC_LOCAL_PORT + " tcp:" + String.valueOf(PHONE_PORT)); Scanner sc = new Scanner(p.getErrorStream()); // If there is some output, it failed to start adb if (sc.hasNext()) { while (sc.hasNext()) System.out.println(sc.next()); System.err.println("Cannot start the Android debug bridge"); return; } initializeConnection(); } catch (Exception e) { System.err.println(e.toString()); } } static Socket socket; public static void initializeConnection() { // Create socket connection try { socket = new Socket("localhost", PC_LOCAL_PORT); ObjectOutputStream oos = new ObjectOutputStream( socket.getOutputStream()); oos.writeObject("lalala"); oos.close(); socket.close(); } catch (UnknownHostException e) { System.err.println("Socket connection problem (Unknown host)" + e.getStackTrace()); e.printStackTrace(); } catch (IOException e) { System.err.println("Could not initialize I/O on socket"); e.printStackTrace(); } } }
--结束END--
本文标题: adb forword通信怎么在android移动端与PC端中使用
本文链接: https://lsjlt.com/news/223755.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0