Skip to content

Commit

Permalink
Uploads file from downloads app
Browse files Browse the repository at this point in the history
  • Loading branch information
jksinton committed Apr 20, 2015
1 parent e820c4f commit 1ba1dfe
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion oc_jb_workaround/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-19
target=android-21
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
# project structure.

# Project target.
target=android-19
target=android-21
android.library.reference.1=actionbarsherlock/library
android.library.reference.2=owncloud-android-library
2 changes: 2 additions & 0 deletions src/com/owncloud/android/files/services/FileUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ private void updateOCFile(OCFile file, RemoteFile remoteFile) {
private OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType,
FileDataStorageManager storageManager) {

Log_OC.d(TAG, "localPath is " + localPath);
Log_OC.d(TAG, "remotePath is " + remotePath);
// MIME type
if (mimeType == null || mimeType.length() <= 0) {
try {
Expand Down
33 changes: 30 additions & 3 deletions src/com/owncloud/android/ui/activity/Uploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Stack;
import java.util.Vector;

import android.content.ContentUris;
import android.provider.DocumentsContract;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.AlertDialog;
Expand Down Expand Up @@ -428,11 +430,12 @@ public void uploadFiles() {
for (Parcelable mStream : mStreamsToUpload) {

Uri uri = (Uri) mStream;
Log_OC.d(TAG, "uri scheme is " + uri.getScheme());
if (uri !=null) {
if (uri.getScheme().equals("content")) {

String mimeType = getContentResolver().getType(uri);

Log_OC.d(TAG, "mime type is " + mimeType);
if (mimeType.contains("image")) {
String[] CONTENT_PROJECTION = { Images.Media.DATA,
Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE,
Expand Down Expand Up @@ -476,8 +479,32 @@ else if (mimeType.contains("audio")) {

}
else {
String filePath = Uri.decode(uri.toString()).replace(uri.getScheme() +
"://", "");
String filePath = "";
String id = DocumentsContract.getDocumentId(uri);
Uri contentUri = ContentUris.withAppendedId( Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

Log_OC.d(TAG, "contentUri.getPath() is " + contentUri.getPath());
Log_OC.d(TAG, "contentUri.toString() is " + contentUri.toString());
Log_OC.d(TAG, "Uri.decode(contentUri.toString()) is " + Uri.decode(contentUri.toString()));

Cursor cursor = null;
String column = "_data";
String[] projection = { column };
cursor = getContentResolver().query(contentUri, projection, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column);
Log_OC.d(TAG,"cursor.getString() is " + cursor.getString(index));
filePath = cursor.getString(index);
}
/*Cursor c = getContentResolver().query(uri, null, null, null, null);
c.moveToFirst();
for(int col=0; col < c.getColumnCount(); col++) {
String colName = c.getColumnName(col);
Log_OC.d(TAG,"ColumnName for col " + Integer.toString(col) + " is " + colName);
Log_OC.d(TAG,"getString for col " + Integer.toString(col) + " is " + c.getString(col));
}*/
//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")) {
Expand Down
2 changes: 1 addition & 1 deletion tests/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-19
target=android-21

0 comments on commit 1ba1dfe

Please sign in to comment.