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

The following examples show how to use android.provider.DocumentsContract#renameDocument() . 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: DocumentTreeFS.java    From edslite with GNU General Public License v2.0 8 votes vote down vote up
public DocumentPath rename(String newName) throws IOException
{
    try
    {
        Path p = getParentPath();
        if(p!=null)
        {
            p = p.combine(newName);
            if(p.exists())
                p.getFile().delete();
        }
    }
    catch (IOException ignored) {}

    final Uri newUri = DocumentsContract.renameDocument(_context.getContentResolver(), getDocumentUri(), newName);
    if (newUri == null)
        throw new IOException("Rename failed");
    else
        return new DocumentPath(newUri);
}
 
Example 2
Source File: AdapterDocuments.java    From microMathematics with GNU General Public License v3.0 8 votes vote down vote up
@Override
public boolean renameItem(int position, String newName)
{
    ContentResolver cr = ctx.getContentResolver();
    Item item = items[position - 1];
    Uri new_uri = null;
    try
    {
        new_uri = DocumentsContract.renameDocument(cr, (Uri) item.origin, newName);
    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
        return false;
    }
    if (new_uri == null)
    {
        return false;
    }
    item.origin = new_uri;
    notifyRefr(newName);
    return true;
}
 
Example 3
Source File: DocumentsContractApi21.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static Uri renameTo(Context context, Uri self, String displayName) {
    try {
        return DocumentsContract.renameDocument(context.getContentResolver(), self, displayName);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 4
Source File: DocumentsContractApi21.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static Uri renameTo(Context context, Uri self, String displayName) {
    try {
        return DocumentsContract.renameDocument(context.getContentResolver(), self, displayName);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 5
Source File: DocumentsContractApi21.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static Uri renameTo(Context context, Uri self, String displayName) {
    try {
        return DocumentsContract.renameDocument(context.getContentResolver(), self, displayName);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 6
Source File: DocumentsContractApi21.java    From UniFile with Apache License 2.0 5 votes vote down vote up
public static Uri renameTo(Context context, Uri self, String displayName) {
    try {
        return DocumentsContract.renameDocument(context.getContentResolver(), self, displayName);
    } catch (Exception e) {
        // Maybe user ejects tf card
        Log.e(TAG, "Failed to renameTo", e);
        return null;
    }
}
 
Example 7
Source File: DocumentsContractApi21.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public static Uri renameTo(Context context, Uri self, String displayName) {
    return DocumentsContract.renameDocument(context.getContentResolver(), self, displayName);
}