Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
- startActivityForResult(intent, REQUEST_CODE_OPEN_DIRECTORY);
- private String copyFile(String inputPath, String inputFile, Uri treeUri) {
- InputStream in = null;
- OutputStream out = null;
- String error = null;
- DocumentFile pickedDir = DocumentFile.fromTreeUri(getActivity(), treeUri);
- String extension = inputFile.substring(inputFile.lastIndexOf(".")+1,inputFile.length());
- try {
- DocumentFile newFile = pickedDir.createFile("audio/"+extension, inputFile);
- out = getActivity().getContentResolver().openOutputStream(newFile.getUri());
- in = new FileInputStream(inputPath + inputFile);
- byte[] buffer = new byte[1024];
- int read;
- while ((read = in.read(buffer)) != -1) {
- out.write(buffer, 0, read);
- }
- in.close();
- // write the output file (You have now copied the file)
- out.flush();
- out.close();
- } catch (FileNotFoundException fnfe1) {
- error = fnfe1.getMessage();
- } catch (Exception e) {
- error = e.getMessage();
- }
- return error;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement