List of usage examples for android.os FileUtils deleteOlderFiles
@UnsupportedAppUsage public static boolean deleteOlderFiles(File dir, int minCount, long minAgeMs)
From source file:com.android.shell.BugreportReceiver.java
@Override public void onReceive(Context context, Intent intent) { final File bugreportFile = getFileExtra(intent, EXTRA_BUGREPORT); final File screenshotFile = getFileExtra(intent, EXTRA_SCREENSHOT); // Files are kept on private storage, so turn into Uris that we can // grant temporary permissions for. final Uri bugreportUri = FileProvider.getUriForFile(context, AUTHORITY, bugreportFile); final Uri screenshotUri = FileProvider.getUriForFile(context, AUTHORITY, screenshotFile); Intent sendIntent = buildSendIntent(context, bugreportUri, screenshotUri); Intent notifIntent;/* ww w .j a v a 2 s. c om*/ // Send through warning dialog by default if (getWarningState(context, STATE_SHOW) == STATE_SHOW) { notifIntent = buildWarningIntent(context, sendIntent); } else { notifIntent = sendIntent; } notifIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Notification.Builder builder = new Notification.Builder(context); builder.setSmallIcon(com.android.internal.R.drawable.stat_sys_adb); builder.setContentTitle(context.getString(R.string.bugreport_finished_title)); builder.setTicker(context.getString(R.string.bugreport_finished_title)); builder.setContentText(context.getString(R.string.bugreport_finished_text)); builder.setContentIntent( PendingIntent.getActivity(context, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.setAutoCancel(true); NotificationManager.from(context).notify(TAG, 0, builder.build()); // Clean up older bugreports in background final PendingResult result = goAsync(); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { FileUtils.deleteOlderFiles(bugreportFile.getParentFile(), MIN_KEEP_COUNT, MIN_KEEP_AGE); result.finish(); return null; } }.execute(); }