List of usage examples for android.support.v4.provider DocumentFile getUri
public abstract Uri getUri();
From source file:com.callrecorder.android.RecordingsAdapter.java
private void sendMail(String fileName) { DocumentFile file = FileHelper.getStorageFile(context).findFile(fileName); Uri uri = FileHelper.getContentUri(context, file.getUri()); Intent sendIntent = new Intent(Intent.ACTION_SEND) .putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.mail_subject)) .putExtra(Intent.EXTRA_TEXT, context.getString(R.string.mail_body)) .putExtra(Intent.EXTRA_STREAM, uri).setData(uri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .setType("audio/3gpp"); context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.send_mail))); }
From source file:de.k3b.android.toGoZip.ZipStorageDocumentFile.java
/** * {@inheritDoc}/* ww w .j av a 2 s. c om*/ */ @Override public String getFullZipUriOrNull() { DocumentFile zipFile = getDocumentFile(ZipStorage.ZipInstance.current); if (zipFile != null) return zipFile.getUri().toString(); return null; }
From source file:org.dkf.jed2k.android.LollipopFileSystem.java
private static boolean write(Context context, DocumentFile f, byte[] data) { InputStream inStream = null;/*from w w w.j a v a2 s . c o m*/ OutputStream outStream = null; try { inStream = new ByteArrayInputStream(data); outStream = openOutputStream(context, f); byte[] buffer = new byte[16384]; // MAGIC_NUMBER int bytesRead; while ((bytesRead = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, bytesRead); } } catch (Exception e) { LOG.error("Error when writing bytes to {} {}", f.getUri(), e); return false; } finally { IOUtils.closeQuietly(inStream); IOUtils.closeQuietly(outStream); } return true; }
From source file:de.k3b.android.toGoZip.ZipStorageDocumentFile.java
/** * {@inheritDoc}//from w ww. j av a 2s .c o m */ @Override public InputStream createInputStream() throws FileNotFoundException { DocumentFile zipFile = directory.findFile(filename); if (zipFile != null) return context.getContentResolver().openInputStream(zipFile.getUri()); return null; }
From source file:com.frostwire.android.LollipopFileSystem.java
private static boolean write(Context context, DocumentFile f, byte[] data) { InputStream inStream = null;//from w ww . j a v a 2s . c o m OutputStream outStream = null; try { inStream = new ByteArrayInputStream(data); outStream = openOutputStream(context, f); byte[] buffer = new byte[16384]; // MAGIC_NUMBER int bytesRead; while ((bytesRead = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, bytesRead); } } catch (Throwable e) { LOG.error("Error when writing bytes to " + f.getUri(), e); return false; } finally { IOUtils.closeQuietly(inStream); IOUtils.closeQuietly(outStream); } return true; }
From source file:freed.cam.apis.sonyremote.modules.PictureModuleSony.java
@Override public void onPictureTaken(URL url) { File file = new File(cameraUiWrapper.getActivityInterface().getStorageHandler() .getNewFilePath(appSettingsManager.GetWriteExternal(), ".jpg")); try {//from w ww.ja va2 s . c o m file.createNewFile(); } catch (IOException ex) { ex.printStackTrace(); } InputStream inputStream = null; OutputStream output = null; try { inputStream = new BufferedInputStream(url.openStream()); if (VERSION.SDK_INT <= VERSION_CODES.LOLLIPOP || VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && !appSettingsManager.GetWriteExternal()) output = new FileOutputStream(file); else { DocumentFile df = cameraUiWrapper.getActivityInterface().getFreeDcamDocumentFolder(); DocumentFile wr = df.createFile("image/jpeg", file.getName()); output = cameraUiWrapper.getContext().getContentResolver().openOutputStream(wr.getUri()); } int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; int len = 0; while ((len = inputStream.read(buffer)) != -1) { output.write(buffer, 0, len); } } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (inputStream != null) inputStream.close(); } catch (IOException ex) { ex.printStackTrace(); } try { if (output != null) output.close(); } catch (IOException ex) { ex.printStackTrace(); } } cameraUiWrapper.getActivityInterface().ScanFile(file); fireOnWorkFinish(file); }
From source file:io.v.syncslides.lib.DeckImporter.java
private byte[] readImage(DocumentFile dir, String fileName) throws IOException { DocumentFile file = dir.findFile(fileName); if (file == null) { throw new FileNotFoundException("Image file doesn't exist: " + fileName); }/*from w ww .j a v a2 s. c o m*/ return ByteStreams.toByteArray(mContentResolver.openInputStream(file.getUri())); }
From source file:freed.cam.apis.camera1.modules.AbstractVideoModule.java
protected void setRecorderOutPutFile(String s) { if (VERSION.SDK_INT < VERSION_CODES.KITKAT || !appSettingsManager.GetWriteExternal() && VERSION.SDK_INT >= VERSION_CODES.KITKAT) recorder.setOutputFile(s);/*from ww w. j a v a2 s .c o m*/ else { File f = new File(s); DocumentFile df = cameraUiWrapper.getActivityInterface().getFreeDcamDocumentFolder(); DocumentFile wr = df.createFile("*/*", f.getName()); try { fileDescriptor = cameraUiWrapper.getContext().getContentResolver().openFileDescriptor(wr.getUri(), "rw"); recorder.setOutputFile(fileDescriptor.getFileDescriptor()); } catch (FileNotFoundException ex) { ex.printStackTrace(); try { fileDescriptor.close(); } catch (IOException ex1) { ex1.printStackTrace(); } } } }
From source file:freed.viewer.stack.StackActivity.java
private void saveBitmapToFile(Bitmap bitmap, File file) { OutputStream outStream = null; String intsd = StringUtils.GetInternalSDCARD(); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP || file.getAbsolutePath().contains(intsd) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try {/*from w w w . j a va 2s . c o m*/ outStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream); outStream.close(); } catch (IOException e) { e.printStackTrace(); } } else { DocumentFile df = getFreeDcamDocumentFolder(); DocumentFile wr = df.createFile("image/*", file.getName()); try { outStream = getContentResolver().openOutputStream(wr.getUri()); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream); outStream.close(); } catch (IOException e) { e.printStackTrace(); } } MediaScannerManager.ScanMedia(getContext(), file); }
From source file:com.amaze.filemanager.utils.files.FileUtils.java
/** * Open file from OTG//from w ww . j a va2 s . co m */ public static void openunknown(DocumentFile f, Context c, boolean forcechooser, boolean useNewStack) { Intent chooserIntent = new Intent(); chooserIntent.setAction(Intent.ACTION_VIEW); chooserIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); String type = f.getType(); if (type != null && type.trim().length() != 0 && !type.equals("*/*")) { chooserIntent.setDataAndType(f.getUri(), type); Intent activityIntent; if (forcechooser) { if (useNewStack) applyNewDocFlag(chooserIntent); activityIntent = Intent.createChooser(chooserIntent, c.getString(R.string.openwith)); } else { activityIntent = chooserIntent; if (useNewStack) applyNewDocFlag(chooserIntent); } try { c.startActivity(activityIntent); } catch (ActivityNotFoundException e) { e.printStackTrace(); Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show(); openWith(f, c, useNewStack); } } else { openWith(f, c, useNewStack); } }