Import java. io. file; import java. io. fileOutputStream; import java. io. IOException; import java. io. inputStream; import org. apache. http. httpEntity; import org. apache. http. httpResponse; import org. apache. http. client. clientProtocolException; import org. apache. http. client. httpClient; import org. apache. http. client. methods. httpGet; import org. apache. http. impl. client. defaultHttpClient; import android. app. ale RtDialog; import android. app. dialog; import android. app. progressDialog; import android. content. dialogInterface; import android. content. intent; import android.net. uri; import android. OS. bundle; import android. OS. environment; import android. OS. handler; public class Update extends BaseActivity {public ProgressDialog pBar; private Handler handler = new Handler (); @ Override protected void onCreate (Bun Dle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. update); Dialog dialog = new AlertDialog. builder (Update. this ). setTitle ("system update "). setMessage ("new version found. Please update it! ") // Set the content. setPositiveButton ("OK", // set the OK button new DialogInterface. onClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {pBar = new ProgressDialog (Update. this); pBar. setTitle ("downloading"); pBar. setMessage ("Please wait... "); pBar. setProgressStyle (ProgressDialog. STYLE_SPINNER); downFile ("http: // url: 8765/OA.apk ");}}). setNegativeButton ("cancel", new DialogInterface. onClickListener () {p Ublic void onClick (DialogInterface dialog, int whichButton) {// click the "cancel" button to exit the program }}). create (); // create // display the dialog box dialog. show ();} void downFile (final String url) {pBar. show (); new Thread () {public void run () {HttpClient client = new DefaultHttpClient (); // params [0] indicates the connected url HttpGet get = new HttpGet (url); HttpResponse response; try {response = client.exe cute (get); HttpEntity entity = response. getE Ntity (); long length = entity. getContentLength (); InputStream is = entity. getContent (); FileOutputStream fileOutputStream = null; if (is! = Null) {File file = new File (Environment. getExternalStorageDirectory (), "OA.apk"); fileOutputStream = new FileOutputStream (file); byte [] buf = new byte [1024]; int ch =-1; int count = 0; while (ch = is. read (buf ))! =-1) {// baos. write (buf, 0, ch); fileOutputStream. write (buf, 0, ch); count + = ch; if (length> 0) {}} fileOutputStream. flush (); if (fileOutputStream! = Null) {fileOutputStream. close () ;}down () ;}catch (ClientProtocolException e) {// TODO Auto-generated catch block e. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch block e. printStackTrace ();}}}. start ();} void down () {handler. post (new Runnable () {public void run () {pBar. cancel (); update () ;}}) ;}void update () {Intent intent = new Intent (Intent. ACTION_VIEW); intent. setDataAndType (Uri. fromFile (new File ("/sdcard/OA.apk"), "application/vnd. android. package-archive "); startActivity (intent );}}