Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1.  
  2. import java.io.File;
  3.  
  4. import android.app.Activity;
  5. import android.content.Intent;
  6. import android.net.Uri;
  7. import android.os.Bundle;
  8. import android.os.Environment;
  9.  
  10. public class UpdateApp extends Activity implements CallBackUpdateApp {
  11.     @Override
  12.     protected void onCreate(Bundle savedInstanceState) {
  13.         super.onCreate(savedInstanceState);
  14.         String url = getIntent().getExtras().getString("url");
  15.         if (url != null) {
  16.             UpdateAsyncTask task = new UpdateAsyncTask(UpdateApp.this, this,
  17.                     url);
  18.             task.execute();
  19.         }
  20.     }
  21.  
  22.     @Override
  23.     public void processResponse() {
  24.         File SDCardRoot = Environment.getExternalStorageDirectory();
  25.         File file = new File(SDCardRoot, "File.apk");
  26.         Intent intent = new Intent(Intent.ACTION_VIEW);
  27.         intent.setDataAndType(Uri.fromFile(file),
  28.                 "application/vnd.android.package-archive");
  29.         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  30.         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  31.         startActivity(intent);
  32.         finish();
  33.     }
  34. }
  35.  
  36. interface CallBackUpdateApp {
  37.     /**
  38.      * Used getting response from async task and sending back to parent activity
  39.      *
  40.      * @param response
  41.      *            : response received by webService
  42.      */
  43.     public void processResponse();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement