Java Code Examples for android.content.Context#deleteFile()

The following examples show how to use android.content.Context#deleteFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataProvider.java    From callmeter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Upgrade table.
 *
 * @param db {@link SQLiteDatabase}
 * @throws IOException IOException
 */
public static void onUpgrade(final Context context, final SQLiteDatabase db)
        throws IOException {
    Log.w(TAG, "Upgrading table: " + TABLE);

    String fn = TABLE + ".bak";
    context.deleteFile(fn);
    ObjectOutputStream os = new ObjectOutputStream(context.openFileOutput(fn,
            Context.MODE_PRIVATE));
    backup(db, TABLE, PROJECTION, null, null, null, os);
    os.close();
    ObjectInputStream is = new ObjectInputStream(context.openFileInput(fn));
    onCreate(db);
    reload(db, TABLE, is);
    is.close();
}
 
Example 2
Source File: CrashManager.java    From apigee-android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes all stack traces and meta files from files dir.
 * 
 * @param context The context to use. Usually your Activity object.
 */
public static void deleteStackTraces(Context context) {
  Log.d(ClientLog.TAG_MONITORING_CLIENT, "Looking for exceptions in: " + Constants.FILES_PATH);
  String[] list = searchForStackTraces();

  if ((list != null) && (list.length > 0)) {
    Log.d(ClientLog.TAG_MONITORING_CLIENT, "Found " + list.length + " stacktrace(s).");

    for (int index = 0; index < list.length; index++) {
  	  String fileName = list[index];
  	  
      try {
        Log.d(ClientLog.TAG_MONITORING_CLIENT, "Delete stacktrace " + fileName + ".");
        deleteStackTrace(context, list[index]);
        context.deleteFile(list[index]);
      } 
      catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
}
 
Example 3
Source File: DataProvider.java    From callmeter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Upgrade table.
 *
 * @param db {@link SQLiteDatabase}
 * @throws IOException IOException
 */
public static void onUpgrade(final Context context, final SQLiteDatabase db)
        throws IOException {
    Log.w(TAG, "Upgrading table: " + TABLE);

    String fn = TABLE + ".bak";
    context.deleteFile(fn);
    ObjectOutputStream os = new ObjectOutputStream(context.openFileOutput(fn,
            Context.MODE_PRIVATE));
    backup(db, TABLE, PROJECTION, null, null, null, os);
    os.close();
    ObjectInputStream is = new ObjectInputStream(context.openFileInput(fn));
    onCreate(db);
    reload(db, TABLE, is);
    is.close();
}
 
Example 4
Source File: FileUtilsTest.java    From PainlessMusicPlayer with Apache License 2.0 6 votes vote down vote up
@Test
public void testWritePrivateFile() throws Exception {
    final byte[] data = new byte[] {
            0x1, 0x2, 0x3, 0x4, 0x8
    };

    final String fileName = "testFileForWrite";
    final Context context = RuntimeEnvironment.application;
    context.deleteFile(fileName);

    FileUtils.writeOrDeletePrivateFile(context, fileName, data);

    final InputStream is = context.openFileInput(fileName);
    final byte[] read = ByteStreams.toByteArray(is);

    assertArrayEquals(data, read);
}
 
Example 5
Source File: TraceInfoCatcher.java    From pre-dem-android with MIT License 6 votes vote down vote up
/**
 * Deletes the give filename and all corresponding files (same name,
 * different extension).
 */
private static void deleteStackTrace(WeakReference<Context> weakContext, String filename) {
    Context context = null;
    if (weakContext != null) {
        context = weakContext.get();
        if (context != null) {
            context.deleteFile(filename);

            String user = filename.replace(".anr", ".user");
            context.deleteFile(user);

            String contact = filename.replace(".anr", ".contact");
            context.deleteFile(contact);

            String description = filename.replace(".anr", ".description");
            context.deleteFile(description);
        }
    }
}
 
Example 6
Source File: CertificateBlacklistInstrumentationTests.java    From mapbox-events-android with MIT License 5 votes vote down vote up
@Before
public void setup() {
  Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
  context.deleteFile("MapboxBlacklist");
  setSystemPrefs();

  ConfigurationClient configurationClient = new ConfigurationClient(context,
    TelemetryUtils.createFullUserAgent("AnUserAgent", context), "anAccessToken", new OkHttpClient());
  this.certificateBlacklist = new CertificateBlacklist(context, configurationClient);
}
 
Example 7
Source File: GesturesDataUtils.java    From ibm-wearables-android-sdk with Apache License 2.0 5 votes vote down vote up
static public void deleteGesture(Context context, String gestureName){

        //delete the file from the local storage
        context.deleteFile(gestureName + GESTURE_NAME_SUFFIX);

        //remove the gesture pref
        ApplicationPreferences.removeGesture(context,gestureName);
    }
 
Example 8
Source File: ProfileManager.java    From android with GNU General Public License v3.0 5 votes vote down vote up
public void removeProfile(Context context, VpnProfile profile) {
    String vpnentry = profile.getUUID().toString();
    profiles.remove(vpnentry);
    saveProfileList(context);
    context.deleteFile(vpnentry + ".vp");
    if (mLastConnectedVpn == profile)
        mLastConnectedVpn = null;

}
 
Example 9
Source File: BitmapEncoder.java    From cloudinary_android with MIT License 5 votes vote down vote up
protected final String saveFile(Context context, Bitmap resource, int quality, Format format) throws ResourceCreationException {
    FileOutputStream fos = null;
    String fileName = UUID.randomUUID().toString();
    String file = null;
    try {

        fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
        resource.compress(adaptFormat(format), quality, fos);
        resource.recycle();
        file = fileName;
    } catch (java.io.FileNotFoundException e) {
        throw new ResourceCreationException("Could not create new file");
    } finally {
        if (fos != null) {
            try {
                fos.close();
                if (StringUtils.isBlank(file)) {
                    // failed, delete the file just in case it's there:
                    context.deleteFile(fileName);
                }
            } catch (IOException ignored) {
            }
        }
    }

    return file;
}
 
Example 10
Source File: FileUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void deleteAllApiFileCache(Context context) {
    if (context != null) {
        String[] fileNames = context.fileList();
        if (!BaseTypeUtils.isArrayEmpty(fileNames)) {
            synchronized (fileNames) {
                for (String cacheName : fileNames) {
                    context.deleteFile(cacheName);
                }
            }
        }
    }
}
 
Example 11
Source File: FileUtils.java    From Varis-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the file in internal memory
 *
 * @param fileName File name
 * @param context  Context
 */
public static void deleteInternalFile(String fileName, Context context) {
    try {
        context.deleteFile(fileName);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 12
Source File: ProfileManager.java    From SimpleOpenVpn-Android with Apache License 2.0 5 votes vote down vote up
public void removeProfile(Context context, VpnProfile profile) {
    String vpnentry = profile.getUUID().toString();
    profiles.remove(vpnentry);
    saveProfileList(context);
    context.deleteFile(vpnentry + ".vp");
    if (mLastConnectedVpn == profile)
        mLastConnectedVpn = null;

}
 
Example 13
Source File: AndroidStorage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
static void deleteStateForTest(Context context) {
  context.deleteFile(STATE_FILENAME);
}
 
Example 14
Source File: FileUtils.java    From letv with Apache License 2.0 4 votes vote down vote up
public static void deleteApiFileCache(Context context, String cacheName) {
    if (context != null && !TextUtils.isEmpty(cacheName)) {
        context.deleteFile(cacheName);
    }
}
 
Example 15
Source File: AndroidStorage.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
static void deleteStateForTest(Context context) {
  context.deleteFile(STATE_FILENAME);
}
 
Example 16
Source File: TiclStateManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Deletes {@link #TICL_STATE_FILENAME}. */
public static void deleteStateFile(Context context) {
  context.deleteFile(TICL_STATE_FILENAME);
}
 
Example 17
Source File: Storage.java    From react-native-secure-key-store with ISC License 4 votes vote down vote up
public static void resetValues(Context context, String[] filenames) {
    for(String filename : filenames) {
        context.deleteFile(filename);
    }
}
 
Example 18
Source File: TiclStateManager.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Deletes {@link #TICL_STATE_FILENAME}. */

public static void deleteStateFile(Context context) {
  context.deleteFile(TICL_STATE_FILENAME);
}
 
Example 19
Source File: Utils.java    From ghwatch with Apache License 2.0 2 votes vote down vote up
/**
 * Delete file from persistent store.
 *
 * @param context
 * @param file    to delete
 * @return true if really deleted
 */
public static boolean deleteFromStore(Context context, File file) {
  return context.deleteFile(file.getName());
}
 
Example 20
Source File: FileObjectUtil.java    From fit with Apache License 2.0 2 votes vote down vote up
/**
 * Delete the given private file associated with this Context's application package.
 *
 * @param context {@link Context}
 * @param name The name of the file to delete; can not contain path separators.
 * @return true if the file was successfully deleted; else false.
 * @since 1.0.1
 */
public static boolean deleteFile(Context context, String name) {
  return context.deleteFile(name);
}