android 实现apk下载展现通知栏

来源:互联网 发布:数据表格平台 编辑:程序博客网 时间:2024/05/21 14:00
   
private static String savePath;private static String saveFileName;private static  int id =1;private static NotificationManager mNotifyManager;private static NotificationCompat.Builder mBuilder ;

    savePath =  Environment.getExternalStorageDirectory()  + "/HJXimg/";    saveFileName = savePath + "huixueyun_app_pro.apk";    mNotifyManager = (NotificationManager) homeActivity.getSystemService(Context.NOTIFICATION_SERVICE);    mBuilder = new NotificationCompat.Builder(homeActivity);    mBuilder.setContentTitle("版本升级").setContentText("下载中,请稍等……").setSmallIcon(R.mipmap.yh_logo);    mBuilder.setProgress(100, 0,false);    mNotifyManager.notify(id, mBuilder.build());    HttpUtils utils = new HttpUtils();    utils.download(fileurl, saveFileName, new RequestCallBack<File>() {        @Override        public void onFailure(HttpException arg0, String arg1) {            // TODO Auto-generated method stub            Toast.makeText(homeActivity,"下载失败!",Toast.LENGTH_SHORT).show();        }        @Override        public void onSuccess(ResponseInfo<File> arg0) {            // TODO Auto-generated method stub            LLog.e("argo--");            mBuilder.setProgress(0, 0,false).setContentTitle("下载完成").setContentText("");            mNotifyManager.notify(id, mBuilder.build());            installApk(saveFileName,homeActivity);        }        @Override        public void onLoading(long total, long current, boolean isUploading) {            int currentNum = (int) (100*current/total);            mBuilder.setProgress(100, currentNum,false);            mNotifyManager.notify(id, mBuilder.build());        }    });}private static void installApk(String saveFileName, HomeActivity homeActivity) {    File apkfile = new File(saveFileName);    if (!apkfile.exists()) {        return;    }    Intent i = new Intent(Intent.ACTION_VIEW);    i.setDataAndType(Uri.parse("file://" + apkfile.toString()), "application/vnd.android.package-archive");    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    homeActivity.startActivity(i);}
阅读全文
1 0
原创粉丝点击