First step: Start Tomcat and add the following JSON file to Tomcat
{"Version": "2.0", "description": "I am the latest, to download I put", "Apkurl": "http://192.168.1.103:8080/zaizaimobilesafe-2.0.apk"}
Step two: Implement a function to display the network access server to obtain the Server data function function
Private void chackupdate () { /* defines a message object that is passed as a handler parameter for data transfer */ final message message = message.obtain (); final long starttime = system.currenttimemillis (); new thread (new runnable () { @Override public void run () { try { /* In the value folder, configure a config. getstring file, store the URL of the server for ease of maintenance, because R.string.serviceurl represents an integer that is an identity of the data, not the data itself */ url url = new url (getString (r.string.serviceurl)); httpurlconnection connection = (httpurlconnection) Url.openconnection (); connection.setrequestmethod ("GET"); connection.setconnecttimeout (4000); int code = Connection.getresponsecode (); if (code == 200) { /* Access Successful */ inputstream is = connection.getinputstream (); /* change the flow into string*/ string result = streamtools.readfromstream (IS); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;LOG.I (TAG, "Networking Success" + result); /*json parsing */ JSONObject object = new Jsonobject (Result); verison = (String) object.get ("Vsersion"); description = (String) Object.get ("description"); apkurl = (String) object.get ("Apkurl"); /* Check if it is a new version */ if (Getversionname (). Equals (Verison)) { message.what = enter_home; /* version consistent, go to the main page */ } else { message.what = SHOW_UPDATE_DIALOG; /* Update new version */ } } } catch (Malformedurlexception e) { message.what = url_error; e.printstAcktrace (); } catch ( Ioexception e) { message.what = NETWORK_ERROR; e.printstacktrace (); } catch (jsonexception e) { message.what = JSON_ERROR; e.printstacktrace (); } finally { long endTime = System.currenttimemillis (); &nHow much time did bsp; /* run */ long dtime = endTime - startTime; /* let the program stay for 2 seconds */ if (dtime < 4000) { try { thread.sleep (4000 - dtime); } catch ( Interruptedexception e) { e.printstacktrace (); } } handler.sendmessage (message); } } }). Start ();}
Define a handler to receive data
Private handler handler = new handler () { @Override public void handlemessage ( MESSAGE&NBSP;MSG) { switch ( Msg.what) { case show_update_dialog:/* displays the upgraded dialog box */ &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;LOG.I (tag, "Show upgrade dialog box"); Showupdatedialog (); break; case enter_home:/* into the main page */ enterhome (); break; case url_error:/*url Error */ enterhome (); Toast.maketext (Getapplicationcontext (), "URL error", toast.length_long). Show (); break; case network_ error:/* Network Error */&NBSP;&NBSP;&Nbsp; Enterhome (); toast.maketext (Getapplicationcontext (), "Network Exception", toast.length_long). Show (); break; case json_error:/*json Parsing Error */ enterhome (); toast.maketext ( Getapplicationcontext (), "JSON parsing error", toast.length_long). Show (); break; default: break; } super.handlemessage (msg); } };
The next pass will give the code for the Entryhome function and the main page.
Aberdeen Security Defender Demo (ii)