版本更新

来源:互联网 发布:蜂鸟众包网络异常 编辑:程序博客网 时间:2024/06/07 07:16
public class MainActivity extends Activity {

    private String url="http://www.oschina.net/uploads/osc-android-v2.6.4-release.apk";
    private String sdPath = "/sdcard/" + System.currentTimeMillis() + "yuyin.apk";
    private Button mBtn;  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       mBtn = (Button) findViewById(R.id.btn);
    }


   public void btn(View v){
       HttpUtils httpUtils=new HttpUtils();
       httpUtils.download(url, sdPath, true, new RequestCallBack<File>() {
        
        @Override
        public void onSuccess(ResponseInfo<File> arg0) {
            mBtn.setText("下载完成");
            //路径
            String path = arg0.result.getPath();
            File file = new File(path);
            Intent intent = new Intent(Intent.ACTION_VIEW);
             intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
            startActivity(intent);
        }
        
        @Override
        public void onFailure(HttpException arg0, String arg1) {
            mBtn.setText("下载失败");
        }
        @Override
        public void onLoading(long total, long current, boolean isUploading) {
            // TODO Auto-generated method stub
            super.onLoading(total, current, isUploading);
            mBtn.setText("正在下载.....");
            ProgressDialog dialog=new ProgressDialog(MainActivity.this);
            dialog.setTitle("正在下载....");
            dialog.setMax((int) total);
            dialog.setProgress((int) current);
            dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            
        }
        @Override
        public void onStart() {
            super.onStart();
            mBtn.setText("开始下载");
        }
    });
   }
    
}

0 0
原创粉丝点击