Java Code Examples for android.provider.DocumentsContract#createDocument()

The following examples show how to use android.provider.DocumentsContract#createDocument() . 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: DocumentsContractApi21.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public static Uri createFile(Context context, Uri self, String mimeType,
        String displayName) {
    try {
        return DocumentsContract.createDocument(context.getContentResolver(), self, mimeType,
                displayName);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 2
Source File: AdapterDocuments.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void createFolder(String new_name)
{
    try
    {
        Uri new_uri = DocumentsContract.createDocument(ctx.getContentResolver(), uri, Document.MIME_TYPE_DIR,
                new_name);
        if (new_uri != null)
        {
            notifyRefr(new_name);
            return;
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    notify(ctx.getString(R.string.fman_create_folder_error, new_name), CommanderIf.OPERATION_FAILED);
}
 
Example 3
Source File: DocumentTreeFS.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
@Override
public com.sovworks.eds.fs.Directory createDirectory(String name) throws IOException
{
    Uri uri = DocumentsContract.createDocument(
            _context.getContentResolver(),
            _path.getDocumentUri(),
            DocumentsContract.Document.MIME_TYPE_DIR,
            name
    );
    if(uri == null)
        throw new IOException("Failed creating folder");
    return new Directory(new DocumentPath(uri));
}
 
Example 4
Source File: DocumentTreeFS.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
@Override
public com.sovworks.eds.fs.File createFile(String name) throws IOException
{
    String mimeType = FileOpsService.getMimeTypeFromExtension(_context, new StringPathUtil(name).getFileExtension());
    Uri uri = DocumentsContract.createDocument(
            _context.getContentResolver(),
            _path.getDocumentUri(),
            mimeType, name);
    if(uri == null)
        throw new IOException("Failed creating file");
    return new File(new DocumentPath(uri));
}
 
Example 5
Source File: DocumentsContractApi21.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static Uri createFile(Context context, Uri self, String mimeType,
        String displayName) {
    try {
        return DocumentsContract.createDocument(context.getContentResolver(), self, mimeType,
                displayName);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 6
Source File: DocumentsContractApi21.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static Uri createFile(Context context, Uri self, String mimeType,
        String displayName) {
    try {
        return DocumentsContract.createDocument(context.getContentResolver(), self, mimeType,
                displayName);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 7
Source File: AdapterDocuments.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Uri newFile(String fileName)
{
    try
    {
        Uri curr = getUri();
        String mime = FileUtils.getMimeByExt(FileUtils.getFileExt(fileName), "*/*");
        return DocumentsContract.createDocument(ctx.getContentResolver(), curr, mime, fileName);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    return null;
}
 
Example 8
Source File: DocumentsContractApi21.java    From UniFile with Apache License 2.0 5 votes vote down vote up
public static Uri createFile(Context context, Uri self, String mimeType,
        String displayName) {
    try {
        return DocumentsContract.createDocument(context.getContentResolver(), self, mimeType,
                displayName);
    } catch (Exception e) {
        // Maybe user ejects tf card
        Log.e(TAG, "Failed to createFile", e);
        return null;
    }
}
 
Example 9
Source File: DirectorySelectionFragment.java    From android-DirectorySelection with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a directory under the directory represented as the uri in the argument.
 *
 * @param uri The uri of the directory under which a new directory is created.
 * @param directoryName The directory name of a new directory.
 */
//VisibileForTesting
void createDirectory(Uri uri, String directoryName) {
    ContentResolver contentResolver = getActivity().getContentResolver();
    Uri docUri = DocumentsContract.buildDocumentUriUsingTree(uri,
            DocumentsContract.getTreeDocumentId(uri));
    Uri directoryUri = null;
    try {
        directoryUri = DocumentsContract
                .createDocument(contentResolver, docUri, Document.MIME_TYPE_DIR, directoryName);
    } catch (IOException e) {
        Log.w(TAG, "IOException", e);
    }
    if (directoryUri != null) {
        Log.i(TAG, String.format(
                "Created directory : %s, Document Uri : %s, Created directory Uri : %s",
                directoryName, docUri, directoryUri));
        Toast.makeText(getActivity(), String.format("Created a directory [%s]",
                directoryName), Toast.LENGTH_SHORT).show();
    } else {
        Log.w(TAG, String.format("Failed to create a directory : %s, Uri %s", directoryName,
                docUri));
        Toast.makeText(getActivity(), String.format("Failed to created a directory [%s] : ",
                directoryName), Toast.LENGTH_SHORT).show();
    }

}
 
Example 10
Source File: DocumentsContractApi21.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static Uri createFile(Context context, Uri self, String mimeType,
        String displayName) {
    return DocumentsContract.createDocument(context.getContentResolver(), self, mimeType,
            displayName);
}