1

In my app I can download a document (docx for example) and open it in QuickOffice. After edditing the document I use the save button and after succesfully saved it, I hit the share button and select my app so I can reupload it.

My problem is, is that the uri i got is not the usual uri you would expect as content://storage/map/file.docx or something like that. I get this from quickoffice:

content://com.quickoffice.android.quickcommon.FileContentProvider/zEV5qmvBJOg2GGWldHMJnNK687Ur6qLGbbMbxj0IxV9cDv2mN8XTGqRrEqU4KIfeZuQNMKMJ_eDx%0AN4YiNZwDShhb4E8%3D%0A

My question is, how can I turn this uri to the real path uri from the file (content://storage/map/file.docx for example)

Carlo Matulessy
  • 975
  • 1
  • 13
  • 27

2 Answers2

1

There is no "real path".

A ContentProvider is welcome to store its content wherever it wants, which may not be a file (e.g., BLOB column in a database) and, even if it is, it may not be a file which you can access (e.g., internal storage for the app hosting the ContentProvider.

Please use the various methods on ContentResolver, such as openInputStream(), to access the contents of this provider.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Hi thanks for your answer, I tried some stuff around the ContentResolver, but couldn't managed to let it work. Could you provide me an example in code how to get from that Uri to the File? – Carlo Matulessy Mar 31 '14 at 08:45
  • @Stitchblade: Call `openInputStream()` on a `ContentResolver` to get an `InputStream` on the content. Copying data from an `InputStream` to a `File` then becomes a matter of standard Java file I/O, of the form that has been around for nearly two decades. See the `copy()` method on [this class](https://github.com/commonsguy/cw-omnibus/blob/master/ContentProvider/Files/src/com/commonsware/android/cp/files/AbstractFileProvider.java) for an example of how to do this. – CommonsWare Mar 31 '14 at 09:31
  • Thanks for your answer CommonsWare. After some research I discoverd that the Quickoffice for Kitkat a different version was than the version < 4.4. Problem is, is that the kitkat version makes use of SAF. So a simple contentresolver wont do the trick. I need some authority or permission to decode the encrypted uri. – Carlo Matulessy Apr 01 '14 at 12:12
  • @Stitchblade: Yeah, I have not dived that deeply into SAF just yet, though it is on my to-do list in the next few weeks. However, the documentation says that you use a `ContentResolver` and `getInputStream()` in general: https://developer.android.com/guide/topics/providers/document-provider.html#client Whether there is anything peculiar to QuickOffice, I can't say. – CommonsWare Apr 01 '14 at 12:48
0

Please use the following code. it worked fine for me.

public static String getContentName(ContentResolver resolver, Uri uri){

String[] ATTACHMENT_META_COLUMNS = {
         OpenableColumns.DISPLAY_NAME,
        OpenableColumns.SIZE
    };
String name = "";
int size= 0;
Cursor metadataCursor = resolver.query(uri,  ATTACHMENT_META_COLUMNS, null, null, null);

if (metadataCursor != null) {
    try {
        if (metadataCursor.moveToFirst()) {
            name = metadataCursor.getString(0);
            size = metadataCursor.getInt(1);
        }
    } finally {
        metadataCursor.close();
    }
}
if (name == null) {
    name = uri.getLastPathSegment();
}

return name;

}