Android10之后,ExifInterface读取照片经纬度信息丢失
创始人
2024-08-20 08:30:15
0
  1. 添加适当的权限

在Android 10中,需要在应用中添加适当的权限才能读取照片文件。在AndroidManifest.xml中添加以下代码:



  1. 使用MediaStore获取经纬度信息

在Android 10之后,ExifInterface可能无法读取照片文件中的GPS信息。相反,您可以使用MediaStore API在新的标记中获取照片的经纬度信息。在以下示例代码中,我们先从MediaStore查询照片的位置信息,然后再从ExifInterface中获取GPS信息。

val projection = arrayOf(
            MediaStore.Images.Media._ID,
            MediaStore.Images.Media.LATITUDE,
            MediaStore.Images.Media.LONGITUDE
        )

val selection = "${MediaStore.Images.Media.LATITUDE} IS NOT NULL AND " +
                "${MediaStore.Images.Media.LONGITUDE} IS NOT NULL"

val query = contentResolver.query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection,
            selection,
            null,
            null
        )

        query?.use { cursor ->
            val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)
            val latitudeColumn =
                cursor.getColumnIndexOrThrow(MediaStore.Images.Media.LATITUDE)
            val longitudeColumn =
                cursor.getColumnIndexOrThrow(MediaStore.Images.Media.LONGITUDE)

            while (cursor.moveToNext()) {
                val id = cursor.getLong(idColumn)
                val latitude = cursor.getDouble(latitudeColumn)
                val longitude = cursor.getDouble(longitudeColumn)

                val exif = ExifInterface(getContentResolver().openInputStream(Uri.parse("${
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI}/$id")))

                exif.setAttribute(
                    ExifInterface.TAG_GPS_LATITUDE,
                    Location.convert(latitude, Location.FORMAT_SECONDS)
                )
                exif.setAttribute(
                    ExifInterface.TAG_GPS_LONGITUDE,
                    Location.convert(longitude, Location.FORMAT_SECONDS)
                )

                exif.saveAttributes()
            }
        }

此代码查询具有非

相关内容

热门资讯

透视玄学!wepoker私人局... 透视玄学!wepoker私人局俱乐部辅助,wepoker有没有插件(透视)wpk教程(有挂脚本)在进...
透视规律!epoker有透视吗... 透视规律!epoker有透视吗,德州透视是真的吗,解密教程(有挂内幕);1、德州透视是真的吗ai辅助...
透视好友房!wepoker到底... 透视好友房!wepoker到底有没有透视,wepoker辅助器如何使用(透视)2025新版(有挂教程...
透视科技!拱趴大菠萝开挂方法,... 透视科技!拱趴大菠萝开挂方法,hhpoker辅助挂是真的吗,微扑克教程(有挂方法);1、进入到hhp...
透视透视!wepoker私人局... 透视透视!wepoker私人局俱乐部,wepoker辅助器怎么弄(透视)技巧教程(有挂详情);1、上...
透视肯定!德普之星辅助软件,w... 透视肯定!德普之星辅助软件,wepoker透视脚本视频,科技教程(有挂方法)1、上手简单,内置详细流...
透视好友房!wepoker轻量... 透视好友房!wepoker轻量版透视系统,wepoker提高好牌率(透视)德州教程(有挂详情)1、w...
透视好友房!wpk真的有透视嘛... 透视好友房!wpk真的有透视嘛,wepokerplus透视脚本免费,2025新版技巧(有挂方法)1、...
透视数据!xpoker辅助器,... 透视数据!xpoker辅助器,红龙poker辅助器免费观看,AI教程(有挂攻略);1、不需要AI权限...
透视好友!wepoker安装教... 透视好友!wepoker安装教程,wejoker辅助软件视频(透视)AA德州教程(有挂教程)1、打开...