- }
- else if (mimeType.contains("audio")) {
- String[] CONTENT_PROJECTION = { Audio.Media.DATA, Audio.Media.DISPLAY_NAME, Audio.Media.MIME_TYPE, Audio.Media.SIZE };
- Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
- c.moveToFirst();
- int index = c.getColumnIndex(Audio.Media.DATA);
- String data = c.getString(index);
- local.add(data);
- remote.add(mUploadPath + c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME)));
-
- }
- else {
- String filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", "");
- // cut everything whats before mnt. It occured to me that sometimes apps send their name into the URI
- if (filePath.contains("mnt")) {
- String splitedFilePath[] = filePath.split("/mnt");
- filePath = splitedFilePath[1];
- }
- final File file = new File(filePath);
- local.add(file.getAbsolutePath());
- remote.add(mUploadPath + file.getName());
- }
+ } else if (mimeType.contains("audio")) {
+ String[] CONTENT_PROJECTION = { Audio.Media.DATA,
+ Audio.Media.DISPLAY_NAME, Audio.Media.MIME_TYPE,
+ Audio.Media.SIZE };
+ Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null,
+ null, null);
+ c.moveToFirst();
+ int index = c.getColumnIndex(Audio.Media.DATA);
+ data = c.getString(index);
+ filePath = mUploadPath +
+ c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME));
+
+ } else {
+ Cursor cursor = getContentResolver().query(uri,
+ new String[]{MediaStore.MediaColumns.DISPLAY_NAME},
+ null, null, null);
+ cursor.moveToFirst();
+ int nameIndex = cursor.getColumnIndex(cursor.getColumnNames()[0]);
+ if (nameIndex >= 0) {
+ filePath = mUploadPath + cursor.getString(nameIndex);
+ }
+ }
+ if (data == null) {
+ CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this);
+ Object[] params = { uri, filePath };
+ try {
+ data = copyTask.execute(params).get();
+ } catch (ExecutionException e) {
+ Log_OC.e(TAG, "ExecutionException " + e);
+ } catch (InterruptedException e) {
+ Log_OC.e(TAG, "InterruptedException " + e);
+ }
+ }
+
+ local.add(data);
+ remote.add(filePath);