コード例 #1
0
      @Override
      protected String doInBackground(Void... unsued) {
        try {
          String response = "";
          String FileName = Common.getNowTime("yyyyMMddHHmmss") + ".csv";

          /*if (isOnline()) {
          	//Response
          	Map<String, String> map = new HashMap<String, String>();
          	map.put("data", sContent);
          	response = NetTool.sendPostRequest(PostDataUrl, map,
          			"UTF-8");
          } else {
          	response = Common.getResText(BarcodeDemoActivity.this, R.string.save_msg) + FileName;
          }*/
          response =
              Common.getResText(BarcodeDemoActivity.this, R.string.save_msg) + " " + FileName;
          writeFile(sContent, FileName);
          return response;
        } catch (Exception e) {
          if (pDialog.isShowing()) pDialog.dismiss();
          Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
          Log.e(e.getClass().getName(), e.getMessage(), e);
          return null;
        }
      }
コード例 #2
0
  private void writeFile(String data, String FileName) {
    if (!Common.checkSDCard()) {
      Common.showDialog(BarcodeDemoActivity.this, Common.getResText(this, R.string.no_sdcard));
      return;
    }

    File root =
        new File(
            android.os.Environment.getExternalStorageDirectory().toString()
                + File.separator
                + "WinmateBarcode"
                + File.separator);
    if (!root.exists()) root.mkdirs();

    FileWriter filewriter = null;
    BufferedWriter out = null;

    try {
      if (!root.canWrite())
        Common.showDialog(
            BarcodeDemoActivity.this, Common.getResText(this, R.string.write_file_err));

      File file = new File(root, FileName);
      filewriter = new FileWriter(file);
      out = new BufferedWriter(filewriter);
      out.write(data);
      out.flush();
    } catch (Exception e) {
      Log.i(TAG, e.toString());
      e.printStackTrace();
    } finally {
      try {
        filewriter.close();
        out.close();
      } catch (IOException e) {
        Log.i(TAG, e.toString());
        e.printStackTrace();
      }
    }
  }
コード例 #3
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    int idGroup1 = 0;

    /* The order position of the item */
    int orderMenuItem1 = Menu.NONE;
    int orderMenuItem2 = Menu.NONE + 1;
    int orderMenuItem3 = Menu.NONE + 2;
    int orderMenuItem4 = Menu.NONE + 3;
    int auto_update_res =
        getAutoUpdateSetting() ? R.string.auto_update_on : R.string.auto_update_off;
    String Version = Common.getResText(this, R.string.version) + ":" + getVersionName();

    menu.add(idGroup1, MENU_LIST1, orderMenuItem1, auto_update_res);
    menu.add(idGroup1, MENU_LIST2, orderMenuItem2, R.string.lang);
    menu.add(idGroup1, MENU_LIST3, orderMenuItem3, Version);
    menu.add(idGroup1, MENU_LIST4, orderMenuItem4, R.string.exit);

    return super.onCreateOptionsMenu(menu);
  }
コード例 #4
0
    @Override
    protected String doInBackground(Void... unsued) {
      try {
        if (!Common.checkSDCard())
          return Common.getResText(BarcodeDemoActivity.this, R.string.no_sdcard);

        String RootPath = android.os.Environment.getExternalStorageDirectory().toString();
        String filePath =
            RootPath + File.separator + "download" + File.separator + "BarcodeDemo.apk";
        boolean Result = false;
        Result = NetTool.DownloadFromUrl(UpdateUrl, filePath);

        if (Result) {
          IOTool.openFile(BarcodeDemoActivity.this, filePath);
          // IOTool.delFile(filePath);
          return "Update sucess";
        } else return "Update fail!!";
      } catch (Exception e) {
        if (pDialog.isShowing()) pDialog.dismiss();
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
        Log.e(e.getClass().getName(), e.getMessage(), e);
        return null;
      }
    }