I am very new to android development and I am trying to get the image exif data selected from gallery. I am able to open the gallery and choose an image. But as I see online I need to get the image path which I am not able to get as
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
is returning 0.
This is my code
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getRealPathFromURI(this,selectedImageUri);
}
}
}
My function to get the real path is this
public static String getRealPathFromURI_API11to18(Context context, Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
String result = null;
CursorLoader cursorLoader = new CursorLoader(
context,
contentUri, proj, null, null, null);
Cursor cursor = cursorLoader.loadInBackground();
if(cursor != null){
int column_index =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
result = cursor.getString(column_index);
}
return result;
}
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "*****"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner ""
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Am I missing something?
ExifInterface(FileDescriptor fileDescriptor)orExifInterface(InputStream inputStream)constructors, or even better see @CommonsWare answer below