Created
August 8, 2013 20:33
-
-
Save choiboi/6188420 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Using the Intent data that the Gallery app returns, this method will | |
* retrive the filepath location of the image that the user have | |
* selected. | |
* | |
* Known issues: This does not work for getting images from Google Drive and | |
* Pisca. | |
*/ | |
public String getGalleryImagePath(Intent data) { | |
Uri imgUri = data.getData(); | |
String filePath = ""; | |
if (data.getType() == null) { | |
// For getting images from default gallery app. | |
String[] filePathColumn = { MediaStore.Images.Media.DATA }; | |
Cursor cursor = getContentResolver().query(imgUri, filePathColumn, null, null, null); | |
cursor.moveToFirst(); | |
int columnIndex = cursor.getColumnIndex(filePathColumn[0]); | |
filePath = cursor.getString(columnIndex); | |
cursor.close(); | |
} else if (data.getType().equals("image/jpeg") || data.getType().equals("image/png")) { | |
// For getting images from dropbox or any other gallery apps. | |
filePath = imgUri.getPath(); | |
} | |
return filePath; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment