コード例 #1
0
  /** TODO: write data */
  public void writeData(String strData, String fileName, int type) {
    String filePath = null;
    OutputStreamWriter myOutWriter = null;
    FileOutputStream fOut = null;

    if (type == TYPE_CALL_LOG) {
      filePath = dataUtils.getRootPath() + FOLDER_CALL_LOG + "/" + fileName;
    } else if (type == TYPE_CONTACT) {
      filePath = dataUtils.getRootPath() + FOLDER_CONTACT + "/" + fileName;
    } else if (type == TYPE_SMS) {
      filePath = dataUtils.getRootPath() + FOLDER_SMS + "/" + fileName;
    }

    try {
      File myFile = new File(filePath);
      myFile.createNewFile();

      fOut = new FileOutputStream(myFile, true);
      myOutWriter = new OutputStreamWriter(fOut);

      myOutWriter.append(strData);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        myOutWriter.close();
        fOut.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } // end-try
  } // end-func
コード例 #2
0
  /** TODO: create app's folder */
  public void createFolderApp() {
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
      Log.d("MyApp", "No SDCARD");
    } else {
      // root's app's folder
      File directory = new File(dataUtils.getRootPath());
      if (directory.exists()) {
        deleteBookFolder(directory);
      }

      directory.mkdir();

      // call log folder
      File calllog = new File(dataUtils.getRootPath() + FOLDER_CALL_LOG + "/");
      calllog.mkdir();

      // contact folder
      File contact = new File(dataUtils.getRootPath() + FOLDER_CONTACT + "/");
      contact.mkdir();

      // sms folder
      File sms = new File(dataUtils.getRootPath() + FOLDER_SMS + "/");
      sms.mkdir();
    }
  }
コード例 #3
0
 /** TODO: delete file data */
 public boolean deleteFileFromSdcard(String fileName, int type) {
   String filePath = null;
   if (type == TYPE_CALL_LOG) {
     filePath = dataUtils.getRootPath() + FOLDER_CALL_LOG + "/" + fileName + "/";
   } else if (type == TYPE_CONTACT) {
     filePath = dataUtils.getRootPath() + FOLDER_CONTACT + "/" + fileName + "/";
   } else if (type == TYPE_SMS) {
     filePath = dataUtils.getRootPath() + FOLDER_SMS + "/" + fileName;
   }
   File file = new File(filePath);
   boolean deleted = file.delete();
   return deleted;
 } // end-func
コード例 #4
0
  /** TODO: read data */
  public String readFileSMS(String fileName) {
    String data = "";

    FileReader file = null;
    BufferedReader br = null;
    try {
      String sCurrentLine;
      file = new FileReader(dataUtils.getRootPath() + FOLDER_SMS + "/" + fileName);
      br = new BufferedReader(file);

      while ((sCurrentLine = br.readLine()) != null) {
        data += sCurrentLine + "\n";
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (br != null) {
          br.close();
        }
        if (file != null) {
          file.close();
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    return data;
  }
コード例 #5
0
  /** TODO: get list files SMS to upload (not today) */
  public List<String> listFileSmsToUpload() {
    List<String> listFile = new ArrayList<String>();

    File directory = new File(dataUtils.getRootPath() + FOLDER_SMS + "/");
    File[] fList = directory.listFiles();

    String sToday = MyUtils.stringFileDate();

    for (File file : fList) {
      if (!file.getName().contains(sToday)) {
        listFile.add(file.getPath());
      }
    }

    return listFile;
  }
コード例 #6
0
  /** TODO: read data */
  public List<ItemCallLog> readFileCallLog(String fileName) {
    List<ItemCallLog> listData = new ArrayList<ItemCallLog>();
    ItemCallLog item = null;

    FileReader file = null;
    BufferedReader br = null;
    try {
      String sCurrentLine;
      file = new FileReader(dataUtils.getRootPath() + FOLDER_CALL_LOG + "/" + fileName);
      br = new BufferedReader(file);

      while ((sCurrentLine = br.readLine()) != null) {

        item = new ItemCallLog();
        String[] stk = sCurrentLine.split("=");

        item.setCallNumber(stk[0]);
        item.setNewNumber(stk[1]);
        listData.add(item);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (br != null) {
          br.close();
        }
        if (file != null) {
          file.close();
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    return listData;
  }