Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting image name of image selected from gallery in android

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();

    }
like image 896
user3415586 Avatar asked May 21 '14 07:05

user3415586


1 Answers

Try this how to get file name from URI

File f = new File(picturePath);
String imageName = f.getName();
like image 167
Shini Avatar answered Oct 13 '22 07:10

Shini