- 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 occurred 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());
- }
+ 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);