Reputation: 2151
I am picking an image via the following intent:
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE);
I'm retrieving the intent by overriding the onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == PICK_IMAGE) {
Uri imageUri = data.getData();
ProfileCalls.editProfileImage(imageUri, getContext()); //Ion post data
}
}
I am then trying to get the path of the image in the following way which is throwing the following exception
java.io.FileNotFoundException: /external/images/media/5302 (No such file or directory)
public static void editProfileImage(Uri profileImageUri, final Context context) {
Ion.with(context)
.load("url")
.setMultipartFile("profileImage", "application/json; charset=UTF-8", new File(profileImageUri.getPath()))
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
System.out.print(e);
System.out.print(result);
}
});
}
Upvotes: 0
Views: 113
Reputation: 2151
Here's the answer I later found over here
private static String getPath(Context context, Uri uri) {
String result = null;
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int column_index = cursor.getColumnIndexOrThrow(proj[0]);
result = cursor.getString(column_index);
}
cursor.close();
}
if (result == null) {
result = "Not found";
}
return result;
}
Upvotes: 0