コード例 #1
0
ファイル: BackupAppsTasker.java プロジェクト: zhengzhou/KAM
 @Override
 protected void onPostExecute(ProgressModel aVoid) {
   super.onPostExecute(aVoid);
   if (aVoid != null) {
     onTaskLoading.onErrorExecuting(aVoid.getMsg(), true);
   } else {
     onTaskLoading.onPostExecute(true);
   }
 }
コード例 #2
0
ファイル: BackupAppsTasker.java プロジェクト: zhengzhou/KAM
  @Override
  protected ProgressModel doInBackground(Void... params) {
    List<AppsModel> appsModelList = new AppListCreator(context).getAppList();
    ProgressModel progressModel = new ProgressModel();
    progressModel.setMax(appsModelList.size());
    publishProgress(progressModel);
    try {
      FileUtil fileUtil = new FileUtil();
      zipFile = new ZipFile(fileUtil.getBaseFolderName() + "backup.zip");
      if (!zipFile.isValidZipFile()) {
        if (zipFile.getFile() != null && zipFile.getFile().exists()) zipFile.getFile().delete();
      }
      int count = 0;
      for (AppsModel model : appsModelList) {
        if (model != null) {
          ApplicationInfo packageInfo =
              context.getPackageManager().getApplicationInfo(model.getPackageName(), 0);
          File fileToSave = fileUtil.generateFile(model.getAppName());
          File file = new File(packageInfo.sourceDir);
          if (file.exists()) {
            count++;
            progressModel = new ProgressModel();
            progressModel.setProgress(count);
            progressModel.setFileName(fileToSave.getName());
            publishProgress(progressModel);
            ZipParameters parameters = new ZipParameters();
            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FASTEST);
            parameters.setSourceExternalStream(true);
            parameters.setFileNameInZip(fileToSave.getName());
            zipFile.addFile(file, parameters);
            progressModel = new ProgressModel();
            progressModel.setProgress(count);
            progressModel.setFileName(fileToSave.getName());
            publishProgress(progressModel);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      ProgressModel error = new ProgressModel();
      error.setMsg(e.getMessage());
      return error;
    }

    return null;
  }