Skip to content

Commit

Permalink
Improve ShareAPI to work in more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Nov 28, 2015
1 parent d554993 commit f9f439f
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions app/src/main/java/com/termux/api/ShareAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;

public class ShareAPI {

Expand Down Expand Up @@ -131,8 +129,36 @@ public Cursor query(Uri uri, String[] projection, String selection, String[] sel
File file = new File(uri.getPath());
String fileName = file.getName();

MatrixCursor cursor = new MatrixCursor(new String[]{MediaStore.MediaColumns.DISPLAY_NAME});
cursor.addRow(new Object[]{fileName});
if (projection == null) {
projection = new String[]{
MediaStore.MediaColumns.DISPLAY_NAME,
MediaStore.MediaColumns.SIZE,
MediaStore.MediaColumns._ID
};
}

Object[] row = new Object[projection.length];
for (int i = 0; i < projection.length; i++) {
String column = projection[i];
Object value;
switch (column) {
case MediaStore.MediaColumns.DISPLAY_NAME:
value = file.getName();
break;
case MediaStore.MediaColumns.SIZE:
value = (int) file.length();
break;
case MediaStore.MediaColumns._ID:
value = 1;
break;
default:
value = null;
}
row[i] = value;
}

MatrixCursor cursor = new MatrixCursor(projection);
cursor.addRow(row);
return cursor;
}

Expand Down

0 comments on commit f9f439f

Please sign in to comment.