I have browsed image from gallery and set it to ImageView
now I need to get image name of image that have been set in ImageView
. I have attached my code below.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("req","req"+requestCode);
Log.d("res","res"+resultCode);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
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]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
imageView = (ImageView) findViewById(R.id.imgView);
imageView1 = (ImageView) findViewById(R.id.imgView1);
if(browse == 1){
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
if(browse == 2){
imageView1.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
String resName = getResources().getResourceEntryName(R.id.imgView);
Toast.makeText(getApplicationContext(), "BBB"+resName,Toast.LENGTH_LONG).show();
}
Try this how to get file name from URI
File f = new File(picturePath);
String imageName = f.getName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With