Skip to content

Instantly share code, notes, and snippets.

@passy
Created March 14, 2014 11:57
Show Gist options
  • Save passy/9546385 to your computer and use it in GitHub Desktop.
Save passy/9546385 to your computer and use it in GitHub Desktop.
diff --git a/app/src/main/java/com/twitter/university/exify/MainActivity.java b/app/src/main/java/com/twitter/university/exify/MainActivity.java
index 97669fa..c32c7a9 100644
--- a/app/src/main/java/com/twitter/university/exify/MainActivity.java
+++ b/app/src/main/java/com/twitter/university/exify/MainActivity.java
@@ -7,6 +7,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
+import android.provider.MediaStore;
import android.provider.MediaStore.MediaColumns;
import android.text.TextUtils.TruncateAt;
import android.util.Log;
@@ -32,7 +33,7 @@ public class MainActivity extends Activity implements OnClickListener {
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
private static final TableRow.LayoutParams TABLE_CELL_LAYOUT_PARAMS = new TableRow.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- private static final String[] MEDIA_DATA_ONLY_PROJECTION = {MediaColumns.DATA};
+ private static final String[] MEDIA_DATA_ONLY_PROJECTION = {MediaStore.Images.ImageColumns.DATA};
private static final int FILE_CHOOSE_REQUEST = 1;
private TextView fileSelection;
private Button fileChooser;
@@ -62,8 +63,7 @@ public class MainActivity extends Activity implements OnClickListener {
@Override
public void onClick(View v) {
if (v == this.fileChooser) {
- final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.addCategory(Intent.CATEGORY_OPENABLE);
+ final Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/jpeg");
super.startActivityForResult(intent, FILE_CHOOSE_REQUEST);
}
@@ -86,6 +86,7 @@ public class MainActivity extends Activity implements OnClickListener {
}
}
+
private File getFile(Intent intent) {
Uri uri = intent.getData();
if (uri == null) {
@@ -94,7 +95,9 @@ public class MainActivity extends Activity implements OnClickListener {
final Cursor cursor = super.getContentResolver().query(uri,
MEDIA_DATA_ONLY_PROJECTION, null, null, null);
try {
- return cursor.moveToFirst() ? new File(cursor.getString(0)) : null;
+ return cursor.moveToFirst() ? new File(cursor.getString(cursor.getColumnIndex(
+ MEDIA_DATA_ONLY_PROJECTION[0]))
+ ) : null;
} finally {
cursor.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment