Вопрос

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)

Это было полезно?

Решение

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.

Другие советы

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;

}

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top