Android Auto Update

Source: Internet
Author: User

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

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.