-2

I want to select a picture/movie file via Android gallery. I followed a similar question in SO: Get/pick an image from Android's built-in Gallery app programmatically and this solves the problem somehow.

The question is, in this code, the returned object is of Bitmap type. How can we return a raw file? I mean, I don't want it to be decoded to Bitmap, I just want to receive the file itself, as is.

The following code is part of the solution to this question: Get/pick an image from Android's built-in Gallery app programmatically

Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};

Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
final String filePath = cursor.getString(columnIndex);
cursor.close();    

Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
/* Now you have choosen image in Bitmap format in object "yourSelectedImage". You can use it in way you want! */

So, how can I do that?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Omid1989
  • 419
  • 3
  • 8
  • 17

1 Answers1

1

All you need to do is,

File myRawFile = new File(filePath);

and then use the file to get what you want. You can read more about File class from here,

https://developer.android.com/reference/java/io/File.html

Nilesh Singh
  • 1,750
  • 1
  • 18
  • 30