方法一:
/** 删除图片后通知系统刷新相册 * @param filePath$Name 要删除的文件的绝对路径 * @return 单个文件删除成功返回true,否则返回false */ public static boolean deleteSingleFile(String filePath$Name) { File file = new File(filePath$Name); // 如果文件路径所对应的文件存在,并且是一个文件,则直接删除 if (file.exists() && file.isFile()) { if (file.delete()) { Log.e("--Method--", "Copy_Delete.deleteSingleFile: 删除文件" + filePath$Name + "成功!"); //刷新图库 BaseApplication.CONTEXT.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + filePath$Name+""))); return true; } else { ToastUtils.show("删除文件" + filePath$Name + "失败!"); // Toast.makeText(getApplicationContext(), "删除文件" + filePath$Name + "失败!", Toast.LENGTH_SHORT).show(); return false; } } else { ToastUtils.show("删除文件失败:" + filePath$Name + "不存在!"); // Toast.makeText(getApplicationContext(), "删除文件失败:" + filePath$Name + "不存在!", Toast.LENGTH_SHORT).show(); return false; } }
方法二:
/** * 将图片文件加入到相册 * @param context * @param dstPath 文件的绝对路径 */ public static void ablumUpdate(final Context context, final String dstPath) { if (TextUtils.isEmpty(dstPath) || context == null) return; File file = new File(dstPath); //System.out.println("panyi file.length() = "+file.length()); if (!file.exists() || file.length() == 0) {//文件若不存在 则不操作 return; } ContentValues values = new ContentValues(2); String extensionName = getExtensionName(dstPath); values.put(MediaStore.Images.Media.MIME_TYPE, "image/" + (TextUtils.isEmpty(extensionName) ? "jpeg" : extensionName)); values.put(MediaStore.Images.Media.DATA, dstPath); context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); }