Android获取手机照片的详细信息

1、效果图

Android获取手机照片的详细信息_第1张图片

2、代码

Cursor photoCursor = mContext.getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                null, null, null, null);
        try {
            while (photoCursor.moveToNext()) {
                Photo photo = new Photo();
                //照片路径
                String photoPath = photoCursor.getString(photoCursor.getColumnIndex(MediaStore.Images.Media.DATA));
                //照片日期
                long photoDate = photoCursor.getLong(photoCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN));
                //照片标题
                String photoTitle = photoCursor.getString(photoCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeFile(photoPath, options);
                //照片类型
                String photoType = options.outMimeType;

                //照片长度
                String photoLength = String.valueOf(options.outHeight);

                //照片宽度
                String photoWidth = String.valueOf(options.outWidth);

                File f = new File(photoPath);
                FileInputStream fis = new FileInputStream(f);

                //照片大小
                float size = fis.available()/1000;
                String photoSize = size+"KB";
            photoCursor.close();

        }catch (Exception e) {
        } finally {
            if (photoCursor!= null) photoCursor.close();
        }

 

 

 

你可能感兴趣的:(Android获取手机照片的详细信息)