List of usage examples for android.support.v4.provider DocumentFile getName
public abstract String getName();
From source file:com.callrecorder.android.FileHelper.java
public static List<Recording> listRecordings(Context context) { final DocumentFile directory = getStorageFile(context); DocumentFile[] files = directory.listFiles(); List<Recording> fileList = new ArrayList<>(); for (DocumentFile file : files) { if (!file.getName().matches(Constants.FILE_NAME_PATTERN)) { Log.d(Constants.TAG, String.format("'%s' didn't match the file name pattern", file.getName())); continue; }// w ww .j a va 2s.c o m Recording recording = new Recording(file.getName()); String phoneNum = recording.getPhoneNumber(); recording.setUserName(getContactName(phoneNum, context)); fileList.add(recording); } return fileList; }
From source file:com.amaze.filemanager.filesystem.RootHelper.java
public static HybridFileParcelable generateBaseFile(DocumentFile file, boolean showHidden) { long size = 0; if (!file.isDirectory()) size = file.length();//w w w .j ava 2 s . c o m HybridFileParcelable baseFile = new HybridFileParcelable(file.getName(), parseDocumentFilePermission(file), file.lastModified(), size, file.isDirectory()); baseFile.setName(file.getName()); baseFile.setMode(OpenMode.OTG); return baseFile; }
From source file:com.amaze.carbonfilemanager.filesystem.RootHelper.java
public static BaseFile generateBaseFile(DocumentFile file, boolean showHidden) { long size = 0; if (!file.isDirectory()) size = file.length();//from ww w.j a v a 2s . c o m BaseFile baseFile = new BaseFile(file.getName(), parseDocumentFilePermission(file), file.lastModified(), size, file.isDirectory()); baseFile.setName(file.getName()); baseFile.setMode(OpenMode.OTG); return baseFile; }
From source file:com.pavlospt.rxfile.RxFile.java
private static File fileFromUri(Context context, Uri data) throws Exception { DocumentFile file = DocumentFile.fromSingleUri(context, data); String fileType = file.getType(); String fileName = file.getName(); File fileCreated;//from w w w.j a va 2 s . co m ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver().openFileDescriptor(data, Constants.READ_MODE); InputStream inputStream = new FileInputStream(parcelFileDescriptor.getFileDescriptor()); logDebug("External cache dir:" + context.getExternalCacheDir()); String filePath = context.getExternalCacheDir() + Constants.FOLDER_SEPARATOR + fileName; String fileExtension = fileName.substring((fileName.lastIndexOf('.')) + 1); String mimeType = getMimeType(fileName); logDebug("From Google Drive guessed type: " + getMimeType(fileName)); logDebug("Extension: " + fileExtension); if (fileType.equals(Constants.APPLICATION_PDF) && mimeType == null) { filePath += "." + Constants.PDF_EXTENSION; } if (!createFile(filePath)) { return new File(filePath); } ReadableByteChannel from = Channels.newChannel(inputStream); WritableByteChannel to = Channels.newChannel(new FileOutputStream(filePath)); fastChannelCopy(from, to); from.close(); to.close(); fileCreated = new File(filePath); logDebug("Path for made file: " + fileCreated.getAbsolutePath()); return fileCreated; }
From source file:com.xxxifan.devbox.library.rxfile.RxFile.java
private static File fileFromUri(Context context, Uri data) throws Exception { DocumentFile file = DocumentFile.fromSingleUri(context, data); String fileType = file.getType(); String fileName = file.getName(); File fileCreated;//from w w w . jav a 2s. c o m ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver().openFileDescriptor(data, Constants.READ_MODE); InputStream inputStream = new FileInputStream(parcelFileDescriptor.getFileDescriptor()); Log.e(TAG, "External cache dir:" + context.getExternalCacheDir()); String filePath = context.getExternalCacheDir() + Constants.FOLDER_SEPARATOR + fileName; String fileExtension = fileName.substring((fileName.lastIndexOf('.')) + 1); String mimeType = getMimeType(fileName); Log.e(TAG, "From Drive guessed type: " + getMimeType(fileName)); Log.e(TAG, "Extension: " + fileExtension); if (fileType.equals(Constants.APPLICATION_PDF) && mimeType == null) { filePath += "." + Constants.PDF_EXTENSION; } if (!createFile(filePath)) { return new File(filePath); } ReadableByteChannel from = Channels.newChannel(inputStream); WritableByteChannel to = Channels.newChannel(new FileOutputStream(filePath)); fastChannelCopy(from, to); from.close(); to.close(); fileCreated = new File(filePath); Log.e(TAG, "Path for made file: " + fileCreated.getAbsolutePath()); return fileCreated; }
From source file:com.github.chenxiaolong.dualbootpatcher.switcher.InAppFlashingFragment.java
@Nullable private static String[] getDirectories(Context context, Uri uri) { final ArrayList<String> filenames = new ArrayList<>(); DocumentFile directory = FileUtils.getDocumentFile(context, uri); DocumentFile[] files = directory.listFiles(); if (files == null) { return null; }//from w w w.j a v a 2 s.c o m for (DocumentFile file : files) { if (file.isDirectory()) { filenames.add(file.getName()); } } Collections.sort(filenames); return filenames.toArray(new String[filenames.size()]); }
From source file:com.commonsware.android.documents.consumer.DurablizerService.java
private Uri makeLocalCopy(Uri document) { DocumentFile docFile = buildDocFileForUri(document); Uri result = null;//from ww w. j a va 2 s. c om if (docFile.getName() != null) { File f = new File(getFilesDir(), docFile.getName()); try { FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream out = new BufferedOutputStream(fos); InputStream in = getContentResolver().openInputStream(document); try { byte[] buffer = new byte[8192]; int len = 0; while ((len = in.read(buffer)) >= 0) { out.write(buffer, 0, len); } out.flush(); result = Uri.fromFile(f); } finally { fos.getFD().sync(); out.close(); in.close(); } } catch (Exception e) { Log.e(getClass().getSimpleName(), "Exception copying content to file", e); } } return (result); }
From source file:com.commonsware.android.documents.consumer.DurablizerService.java
@Override protected void onHandleIntent(Intent intent) { Uri document = intent.getData();/* ww w. j a v a2 s. c om*/ boolean weHaveDurablePermission = obtainDurablePermission(document); if (!weHaveDurablePermission) { document = makeLocalCopy(document); } if (weHaveDurablePermission || document != null) { Log.d(getClass().getSimpleName(), document.toString()); DocumentFile docFile = buildDocFileForUri(document); Log.d(getClass().getSimpleName(), "Display name: " + docFile.getName()); Log.d(getClass().getSimpleName(), "Size: " + Long.toString(docFile.length())); EventBus.getDefault().post(new ContentReadyEvent(docFile)); } }
From source file:com.osama.cryptofm.tasks.DeleteTask.java
private void deleteDocFile(DocumentFile docFile) throws IOException { Log.d(TAG, "deleteDocFile: Deleting document file"); publishProgress(docFile.getName()); if (docFile.isDirectory() && docFile.listFiles().length > 0) { for (DocumentFile d : docFile.listFiles()) { deleteDocFile(d);// ww w . ja v a 2 s .co m } } if (!docFile.delete()) { throw new IOException("cannot delete files"); } }
From source file:com.xperia64.timidityae.Globals.java
public static boolean renameDocumentFile(Context c, String from, String subTo) { // From is the full path // subTo is the path without the device prefix. // So /storage/sdcard1/folder/file.mid should be folder/file.mid if (theFold == null) return false; from = from.replace("//", "/"); subTo = subTo.replace("//", "/"); DocumentFile df = DocumentFile.fromTreeUri(c, theFold); String split[] = from.split("/"); int i;/*from w w w .j a va 2 s . c om*/ for (i = 0; i < split.length; i++) { if (split[i].equals(df.getName())) { i++; break; } } DocumentFile xx = df; StringBuilder upper = new StringBuilder(); while (i < split.length) { xx = xx.findFile(split[i++]); upper.append("../"); if (xx == null) { Log.e("TimidityAE Globals", "Rename file error."); break; } } if (xx != null && upper.length() > 3) { return xx.renameTo(upper.substring(0, upper.length() - 3) + subTo); } return false; }