获取从android中的库中选择的图像的图像名称

问题描述 投票:8回答:1

我已经浏览了图库中的图像并将其设置为ImageView现在我需要获取已在ImageView中设置的图像的图像名称。我在下面附上了我的代码。

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

    }
android image gallery
1个回答
14
投票

试试这个how to get file name from URI

File f = new File(picturePath);
String imageName = f.getName();
© www.soinside.com 2019 - 2024. All rights reserved.