X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/da7e13ed5ce67e0da36963cf87ccb3e9610270ee..3cae3d3eb84a0b734ee9ca8a27ee7df29232d90e:/src/com/owncloud/android/ui/activity/FileDisplayActivity.java diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index ad6a072a..2469dcf7 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -49,9 +49,11 @@ import android.os.IBinder; import android.preference.PreferenceManager; import android.provider.DocumentsContract; import android.provider.MediaStore; +import android.provider.OpenableColumns; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; +import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; @@ -691,7 +693,34 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { } if (!remotepath.endsWith(OCFile.PATH_SEPARATOR)) remotepath += OCFile.PATH_SEPARATOR; - remotepath += new File(filepath).getName(); + + if (filepath.startsWith("content://")) { + // The query, since it only applies to a single document, will only return + // one row. There's no need to filter, sort, or select fields, since we want + // all fields for one document. + Cursor cursor = MainApp.getAppContext().getContentResolver() + .query(Uri.parse(filepath), null, null, null, null, null); + + try { + // moveToFirst() returns false if the cursor has 0 rows. Very handy for + // "if there's anything to look at, look at it" conditionals. + if (cursor != null && cursor.moveToFirst()) { + + // Note it's called "Display Name". This is + // provider-specific, and might not necessarily be the file name. + String displayName = cursor.getString( + cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); + Log.i(TAG, "Display Name: " + displayName); + + remotepath += displayName; + } + } finally { + cursor.close(); + } + + } else { + remotepath += new File(filepath).getName(); + } i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath); i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath); @@ -919,7 +948,11 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(getApplicationContext(), contentUri, selection, selectionArgs); - } + } + // Documents providers returned as content://... + else if (isAContentDocument(uri)) { + return uri.toString(); + } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { @@ -1009,6 +1042,15 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { } /** + * + * @param uri The Uri to check. + * @return Whether the Uri is from a content provider as kind "content://..." + */ + public static boolean isAContentDocument(Uri uri) { + return uri.toString().startsWith("content://"); + } + + /** * Pushes a directory to the drop down list * @param directory to push * @throws IllegalArgumentException If the {@link OCFile#isFolder()} returns false.