Getting image name of image selected from gallery in android

I looked at the image from the gallery and set it to ImageView Now I need to get the image of the image that was installed 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(); } 
+7
android image gallery
source share
1 answer

Try how to get file name from URI

 File f = new File(picturePath); String imageName = f.getName(); 
+11
source share

All Articles