Android through the WiFi program debugging, the program requires root permissions to be able.
1, first join the permission
<uses-permission android:name= "Android.permission.INTERNET"/><uses-permission android:name= " Android.permission.ACCESS_WIFI_STATE "/>
2. layout file
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:orientation= "vertical" > <button android:id= "@+id/btn" android:layout_width= " Fill_parent " android:layout_height=" wrap_content " android:text=" @string/open_adb "/> < TextView android:id= "@+id/tv" android:layout_width= "wrap_content" android:layout_height= "Wrap_ Content "/></linearlayout>
3. Java File Code
public class Mainactivity extends Activity {private Button btn;private boolean isopen;private TextView TV; @Overrideprotec Ted void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main); btn = (Button) Findviewbyid (r.id.btn); TV = (TextView) Findviewbyid (r.id.tv); Btn.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {if (!isopen) {tv.settext ("Open command line, The CD command enters the Platform-tools folder in the directory where the SDK is installed, and then enters ADB connect "+ getlocalipaddress () +": 5555 ") btn.settext (" Off "); Execshell (" SetProp service.adb.tcp.port 5555 "); Execshell (" Start adbd "); isOpen = true;} else {Tv.settext (""); Btn.settext ("open"); Execshell ("Stop adbd"); isOpen = false;}});} Private String getlocalipaddress () {Wifimanager Wifimanager = (wifimanager) getsystemservice (Wifi_service); Wifiinfo wifiinfo = Wifimanager.getconnectioninfo ();//Gets a 32-bit integer IP address int ipAddress = wifiinfo.getipaddress ();//return integer address converted to "*.*.*.*" Address return String.Format ("%d.%d.%d.%d", (IpAddress & 0xFF), (IpAddress >> 8 & 0xff), (ipAddress >> & 0xFF), (ipAddress >> & 0xFF));} public static String getipaddress () {try {for (enumeration<networkinterface> en = Networkinterface.getnetworkinterfaces (); En.hasmoreelements ();) {NetworkInterface intf = en.nextelement (); for (enumeration<inetaddress> enumipaddr = intf.getinetaddresses (); Enumipaddr.hasmoreelements ();) {InetAddress inetaddress = enumipaddr.nextelement (); if (!inetaddress.isloopbackaddress () && inetaddress instanceof inet4address) {//if (!inetaddress.isloopbackaddress () && inetaddress//instanceof Inet6Address) { Return inetaddress.gethostaddress (). toString ();}}} catch (Exception e) {e.printstacktrace ();} return null;} public void Execshell (String str) {try {//permission set Process P = Runtime.getruntime (). EXEC ("su");//Get output stream OutputStream Outputstr EAM = P.getoutputstream ();D ataoutputstream dataoutputstream = new DataOutputStream (outputstream);// Writes the command to Dataoutputstream.writebytes (str);/Submit command Dataoutputstream.flush ();//Close stream operation Dataoutputstream.close (); Outputstream.close ();} catch (Throwable t) {t.printstacktrace ();}}}
Very detailed, the source code will not be on the bar.
Android Wireless debugging