Advertisement
Smile_Studio

Rename File Grallery

Jul 16th, 2020
1,670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. public static boolean renameVideoFile(Context mContext, File from, File to) {
  2.         if (from.getParentFile().exists() && from.exists() && from.renameTo(to)) {
  3.             removeMedia(mContext, from);
  4.             addMedia(mContext, to);
  5.             return true;
  6.         } else {
  7.             return false;
  8.         }
  9.     }
  10.  
  11.     public static void addMedia(Context mContext, File file) {
  12.         Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file));
  13.         mContext.sendBroadcast(intent);
  14.     }
  15.  
  16.     public static void removeMedia(Context mContext, File file) {
  17.         try {
  18.             ContentResolver resolver = mContext.getContentResolver();
  19.             resolver.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media.DATA + "=?", new String[]{file.getAbsolutePath()});
  20.         } catch (Exception e){
  21.             Debug.e("--- removeMedia: " + e.getMessage());
  22.         }
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement