I'm rather new to Java (specifically Android). I'm trying to get the user to pick an image from the gallery, and then the app will copy the image from a gallery to a folder in the app's directory (as well as display the picture they have chosen in an imagebutton). However, I get a compiler error of "Unhandled exception type IOException."
This is my code: (Somewhere earlier)
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 2);
(in onActivityResult function)
Uri selectedImage = data.getData(); //data from onActivityResult
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageButton abcd = (ImageButton) findViewById(R.id.btn_addpicture);
abcd.setImageBitmap(BitmapFactory.decodeFile(picturePath));
String command = "cp " + "'" + selectedImage.getPath().toString() + "' '" + getFilesDir().getPath() + "/Images/" + VALUE_NAME + ".jpg";
Runtime.getRuntime().exec(command);
The error comes from the last line. Can anyone explain where I went wrong? I have no idea what the error means