从Android图库中选择图像的获取图像名称 [英] getting image name of image selected from gallery in android

查看:178
本文介绍了从Android图库中选择图像的获取图像名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从图库浏览图像并将其设置为图像视图现在我需要得到那些在图像视图..我设置图像的图像名字附上下面请查看并回复我。

  @覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
    super.onActivityResult(要求code,结果code,数据);
    Log.d(REQ,REQ+请求code);
    Log.d(资源,资源+结果code);    如果(要求code == RESULT_LOAD_IMAGE&放大器;&安培;结果code == RESULT_OK&放大器;&安培;!NULL =数据){
        乌里selectedImage = data.getData();
        的String [] = filePathColumn {MediaStore.Images.Media.DATA};
        光标光标= getContentResolver()查询(selectedImage,
                filePathColumn,NULL,NULL,NULL);
        cursor.moveToFirst();
        INT参数:columnIndex = cursor.getColumnIndex(filePathColumn [0]);
        字符串picturePath = cursor.getString(参数:columnIndex);
        cursor.close();
        ImageView的=(ImageView的)findViewById(R.id.imgView);        imageView1 =(ImageView的)findViewById(R.id.imgView1);        如果(浏览== 1){
            imageView.setImageBitmap(BitmapFactory.de codeFILE(picturePath));
        }
        如果(浏览== 2){
            imageView1.setImageBitmap(BitmapFactory.de codeFILE(picturePath));
        }
        。字符串resName = getResources()getResourceEntryName(R.id.imgView);
        Toast.makeText(getApplicationContext(),BBB+ resName,Toast.LENGTH_LONG).show();    }


解决方案

试试这个的如何从URI 获取文件名

 文件f =新的文件(picturePath);           串imageName = f.getName();

i have browsed image from gallery and set it to image View now i need to get image name of image that have been set in image view ..i have attached my code below please view and reply me

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

这篇关于从Android图库中选择图像的获取图像名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆