Android获取相册图片信息

        val mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
        val orderBy = MediaStore.Images.Media.DATE_TAKEN + " DESC"
        val cursor = AppApplication.getInstance().contentResolver.query(
            mImageUri, null, null, null, orderBy
        )
        while (cursor != null && cursor.moveToNext()) {
            val path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA))
            val name =
                cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.TITLE))
            val exif = ExifInterface(path)
            exif?.let {
                val lalo = FloatArray(2)
                exif.getLatLong(lalo)
                val latitude = lalo.get(0).toString()
                val longitude = lalo.get(1).toString()
                val make = it.getAttribute(ExifInterface.TAG_MAKE)
                val model = it.getAttribute(ExifInterface.TAG_MODEL)
                val width = it.getAttribute(ExifInterface.TAG_IMAGE_WIDTH)
                val height = it.getAttribute(ExifInterface.TAG_IMAGE_LENGTH)
                val time = it.getAttribute(ExifInterface.TAG_DATETIME)
            }
        }
        cursor?.close()

其中获取经纬度的话需要动态申请权限

你可能感兴趣的:(Android,android,相册)