Java Code Examples for android.support.v4.provider.DocumentFile#renameTo()
The following examples show how to use
android.support.v4.provider.DocumentFile#renameTo() .
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: FileUtils.java From Rey-MusicPlayer with Apache License 2.0 | 6 votes |
public static void rename(File file, String fileName) { if (MusicUtils.isFromSdCard(file.getAbsolutePath())) { DocumentFile documentFile = getDocumentFile(file); documentFile.renameTo(fileName); } else { File parentFile = file.getParentFile(); if (!parentFile.exists()) parentFile.mkdir(); File file1 = new File(parentFile, fileName); file.renameTo(file1); file.delete(); } }
Example 2
Source File: Rename.java From Camera-Roll-Android-App with Apache License 2.0 | 6 votes |
private boolean renameFileRemovableStorage(Context context, Uri treeUri, String path, String newFileName) { //keep old paths to remove them from MediaStore afterwards ArrayList<String> oldPaths = FileOperation.Util.getAllChildPaths(new ArrayList<String>(), path); newFilePath = getNewFilePath(path, newFileName); boolean success = false; DocumentFile file = StorageUtil.parseDocumentFile(context, treeUri, new File(path)); if (file != null) { success = file.renameTo(new File(newFilePath).getName()); } //re-scan all paths ArrayList<String> newPaths = FileOperation.Util.getAllChildPaths(new ArrayList<String>(), newFilePath); addPathsToScan(oldPaths); addPathsToScan(newPaths); return success; }
Example 3
Source File: FileUtil.java From FileManager with Apache License 2.0 | 6 votes |
public static boolean renameTarget(String filePath, String newName) { File src = new File(filePath); String temp = filePath.substring(0, filePath.lastIndexOf("/")); File dest = new File(temp + "/" + newName); if (src.renameTo(dest)) { return true; } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { DocumentFile document = DocumentFile.fromFile(src); if (document.renameTo(dest.getAbsolutePath())) { return true; } } } return false; }
Example 4
Source File: SimpleUtils.java From SimpleExplorer with GNU General Public License v3.0 | 6 votes |
public static boolean renameTarget(String filePath, String newName) { File src = new File(filePath); String temp = filePath.substring(0, filePath.lastIndexOf("/")); File dest = new File(temp + "/" + newName); if (src.renameTo(dest)) { return true; } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { DocumentFile document = DocumentFile.fromFile(src); if (document.renameTo(dest.getAbsolutePath())) { return true; } } } return false; }
Example 5
Source File: ZipStorageDocumentFile.java From ToGoZip with GNU General Public License v3.0 | 5 votes |
/** * {@inheritDoc} */ @Override public boolean rename(ZipInstance zipInstanceFrom, ZipInstance zipInstanceTo) { DocumentFile zipFile = directory.findFile(getZipFileNameWithoutPath(zipInstanceFrom)); if (zipFile != null) return zipFile.renameTo(getZipFileNameWithoutPath(zipInstanceTo)); return false; }