1. In the background to maintain an Android version number, every time you enter the app, on the Welcome screen, go to query the latest version number. Compare with the current version of the app.
2. Place the latest app (the latest version number) on the server and provide a URL for the download function (you can maintain a feature that uploads the latest app in the background).
/** * Download App * * @param URL * @return * * Public StaticObjectDownloadpdalookup(String Action,FinalContext mcontext) {String result ="[{\" note\ ": \" Network exception! Please check network!\ ", \" networkflag\ ": true}]";if(! Networkutil.getnetworkstatus ()) {returnResult } String Realurl = s_url_lookup + action; Logutil.i (TAG,""+ Realurl);Try{HttpClient HttpClient =NewHttpClient (); Usernamepasswordcredentials creds =NewUsernamepasswordcredentials (Activityutil.username_c, Activityutil.password_c); Logutil.i (TAG +"User", Activityutil.username_c + Activityutil.password_c); Httpclient.getstate (). SetCredentials (Authscope.any, creds);//Network connection time 10 secondsHttpclient.getparams (). Setparameter (Coreconnectionpnames.connection_timeout, -* +);//server-side return data time 10 secondsHttpclient.getparams (). Setparameter (Coreconnectionpnames.so_timeout, -* +); Postmethod method =NewPostmethod (Realurl); Method.setdoauthentication (true); Method.getparams (). Setparameter (Httpmethodparams.retry_handler,NewDefaulthttpmethodretryhandler (3,false));intStatusCode = Httpclient.executemethod (method);if(StatusCode = = $) {InputStream is; is = Method.getresponsebodyasstream (); String sdcard = environment.getexternalstoragedirectory () +""; String PathName ="/sdcard"+"/pda.apk";//File Store path ///storage/emulated/0/pda.apkFile File =NewFile (PathName); FileOutputStream fos =NewFileOutputStream (file);byte[] buf =New byte[1024x768];intCount =0; while((count = Is.read (BUF))! =-1) {Fos.write (buf,0, count); } fos.close (); Is.close (); OpenFile (file, mcontext); result ="[{\" note\ ": \" Download complete!\ ", \" Status\ ": true}]";returnResult } }Catch(Clientprotocolexception e) {//E.printstacktrace ();result ="[{\" note\ ": \" network protocol exception (clientprotocolexception)!\ ", \" networkflag\ ": true}]";returnResult }Catch(IOException e) {//E.printstacktrace ();result ="[{\" note\ ": \" background or network (IOException) exception!\ ", \" networkflag\ ": true}]";returnResult } result ="[{\" note\ ": \" Unknown error! Please contact developer!\ ", \" networkflag\ ": true}]";returnResult }/** * After downloading the PDA, automatically open the installer. * * @param file * @param mcontext */ Private Static void OpenFile(File file,FinalContext Mcontext) {//TODO auto-generated method stubLogutil.i ("OpenFile", File.getname ()); Intent Intent =NewIntent (); Intent.addflags (Intent.flag_activity_new_task); Intent.setaction (Android.content.Intent.ACTION_VIEW); Intent.setdataandtype (uri.fromfile (file),"Application/vnd.android.package-archive"); Mcontext.startactivity (Intent); }
Android Auto Update