Android Open Source - FastBudget3 Backup Restore

From Project

Back to project page FastBudget3.


The source code is released under:

GNU General Public License

If you think the Android project FastBudget3 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.splitstudio.fastbudget3.db;
//from  w w  w  .  ja  va 2 s .  c  o  m
import static android.content.Intent.ACTION_SEND;
import static android.content.Intent.EXTRA_STREAM;
import static android.content.Intent.createChooser;
import static de.splitstudio.utils.activity.DialogHelper.createAlert;

import java.util.List;


import android.content.Context;
import android.content.Intent;
import de.splitstudio.fastbudget3.R;
import de.splitstudio.utils.activity.DialogHelper;
import de.splitstudio.utils.db.Database;

public class BackupRestore {

  private static final String BACKUP_MIME_TYPE = "application/octet-stream";

  public static void createBackup(Context context) {
    File dest = getFile(context, ".backup");
    if (dest == null) {

    backup(context, dest);
    sendFile(context, dest);

  public static void createCsv(Context context, List<Category> categories) {
    File dest = getFile(context, ".csv");
    if (dest == null) {

    if (createCsvFile(context, categories, dest)) {
      sendFile(context, dest);

  private static void sendFile(final Context context, final File src) {
    DialogHelper.createQuestion(context, R.string.success, R.string.backup_created, R.string.cancel,
      R.string.send_file, new Runnable() {
        public void run() {
          String chooserTitle = context.getString(R.string.send_file);
          Intent intent = new Intent(ACTION_SEND);
          intent.putExtra(EXTRA_STREAM, Uri.fromFile(src));
          context.startActivity(createChooser(intent, chooserTitle));
      }, src.getAbsolutePath());

  private static boolean createCsvFile(Context context, List<Category> categories, File dest) {
    String content = new CsvExport(categories).getContent();
    try {
      FileUtils.write(dest, content);
      return true;
    } catch (IOException e) {
      createAlert(context, R.string.error, R.string.error_write_file, R.string.ok);
      return false;

  private static void backup(final Context context, final File dest) {

  private static File getFile(Context context, String suffix) {
    File externalFilesDir = context.getExternalFilesDir(null);
    if (externalFilesDir == null) {
      DialogHelper.createAlert(context, R.string.warning, R.string.error_no_external_storage, R.string.ok);
      return null;
    String filename = context.getString(R.string.app_name) + suffix;
    return new File(externalFilesDir, filename);


Java Source Code List