Android Backup Issue--reprint

Source: Internet
Author: User
<span id="Label3"></p><p><p>To implement similar peas clips such as communication with PC applications to backup contacts, sms, applications, and the ability to edit this Information.<br>The main use of the ADB,SOCKET,PC app is to connect Android via USB and then send a broadcast to launch the Server-side program in ANDROID.<br>This is the use of c/s communication mode, the Android Terminal application is the server, the PC side is the Client. PC app is launched via the TCP protocol after starting the android terminal<br>Communication.</p></p>first, access to the computer connected to all mobile phones, in front of the VC + + article also refers to the acquisition Method. Only Java is described Here. It's all the Same. With the ADB command ...<p>public static list<device> finddevices () {<br>list<device>devices = new Arraylist<device> ();<br>String str = null;<br>int port = 15000;<br>Process Process = null;<br>Device device = null;<br>string[] devicestr = new string[2];<br>List<string>lines=new arraylist<string> ();<br>try {<br>Process = Runtime.getruntime (). exec ("adb devices");<br>InputStream in = Process.getinputstream ();<br>BufferedReader read=new bufferedreader (new inputstreamreader (in));<br> <br>While ((str=read.readline ())!=null) {<br>Lines.add (str);<br>System.out.println (str);<br>}<br>For (int i=1;i<lines.size () -1;i++) {<br>str = Lines.get (i);<br>Devicestr = Str.split ("");<br>If ("device". equals (devicestr[1])) {<br>device = new device ();<br>Device.setdeviceid (devicestr[0]);<br>Device.setstate (devicestr[1]);<br>The port is specified first;<br>Device.setport (port);<br>port++;<br>Devices.add (device);<br>}<br>}<br>} catch (ioexception E) {<br>E.printstacktrace ();<br>}<br> <br>Return devices;<br>}</p><br>second, Port mapping; Start the app on the phone side<p>public static void Portforwardbydevice (Devices Device) {<br>String A = null;<br>String B = null;<br>String C = null;<br>String d = null;<br>Log logger = Logfactory.getlog (devicefinder.class);<br> <br>A = "adb-s" + Device.getdeviceid () + "shell am broadcast-a notifyservicestop";<br>b = "adb-s" + Device.getdeviceid () + "forward tcp:" +device.getport () + "tcp:12222";<br>c = "adb-s" + Device.getdeviceid () + "shell am broadcast-a notifyservicestart";<br>d= "adb-s" + Device.getdeviceid () + "shell am start-n com.newland.realmobiledetection/com.newland.realmobiledetection. System.activity.WelcomeActivity ";<br>Logger.error ("... Device...a...") +a);<br>Logger.error ("... Device...b...") +b);<br>Logger.error ("... Device...c...") +c);<br>Logger.error ("... Device...d...") +d);<br>try {<br>Runtime.getruntime (). exec (d);<br>Thread.Sleep (1000);<br>Runtime.getruntime (). exec (a);<br>Thread.Sleep (1000);<br>Runtime.getruntime (). exec (b);<br>Thread.Sleep (1000);<br>Runtime.getruntime (). exec (c);<br>Thread.Sleep (1000);<br>Logger.error ("port Mapping Complete: ");<br>} catch (ioexception E) {<br> <br>Logger.error ("abnormal communication with mobile phone" +e.getmessage ());<br>}catch (interruptedexception E) {<br>Logger.error ("thread break exception" +e.getmessage ());<br>}<br> <br>}<br> </p><br>third, the Connection:<p><p>try {<br>InetAddress serveraddr = null;<br>SERVERADDR = Inetaddress.getbyname ("127.0.0.1");<br>Socket = new Socket (serveraddr, pcport);<br>Socket.setkeepalive (true);<br>Socket.setsotimeout (120 * 1000);<br>Bufferedoutputstream out = new Bufferedoutputstream (socket.getoutputstream ());<br>Bufferedinputstream in = new Bufferedinputstream (socket.getinputstream ());<br>Out.write (requestcontent.getbytes ());<br>Out.flush ();<br>Responsecontent=readfromsocket (in);<br>System.out.println (":::::::::::,": ":::::::::::".:......<br>Logger.info (".:::::::::::,"::::::-:::::: (); ";"; ";" +responsecontent);<br>obj = Gson.fromjson (responsecontent, method.getgenericreturntype ());</p></p><br>Mobile app);<p><p>ServerSocket =new Serverscoket (12222);<br><br>Socket socket = Serversocket.accept ();<br><br>out = new Bufferedoutputstream (socket.getoutputstream ());<br>in = new Bufferedinputstream (socket.getinputstream ());</p></p><br><p><p>The implementation is the C/S architecture, you can write the server as an Android service, and then can automatically handle the various client commands.</p></p><p><p>Android Backup Issue--reprint</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.