Remove location permissions and dependencies; switch to release build with signing for Huawei compatibility
This commit is contained in:
@@ -6,9 +6,6 @@
|
||||
<!-- 相机权限 -->
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<!-- 位置权限 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<!-- 硬件功能声明 -->
|
||||
<uses-feature android:name="android.hardware.camera" android:required="true" />
|
||||
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
|
||||
|
||||
@@ -40,8 +40,7 @@ class CameraActivity : AppCompatActivity() {
|
||||
private const val TAG = "LogCam"
|
||||
private const val REQUEST_CODE_PERMISSIONS = 10
|
||||
private val REQUIRED_PERMISSIONS = arrayOf(
|
||||
Manifest.permission.CAMERA,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
Manifest.permission.CAMERA
|
||||
)
|
||||
}
|
||||
|
||||
@@ -51,8 +50,6 @@ class CameraActivity : AppCompatActivity() {
|
||||
private lateinit var photoPreviewLayout: LinearLayout
|
||||
private var imageCapture: ImageCapture? = null
|
||||
private lateinit var cameraExecutor: ExecutorService
|
||||
private var locationManagerHelper: LocationManagerHelper? = null
|
||||
private var currentLocation: Location? = null
|
||||
|
||||
// 存储拍摄的图片URI
|
||||
private val capturedImageUris = mutableListOf<Uri>()
|
||||
@@ -272,42 +269,8 @@ class CameraActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAddressFromLocation(location: Location): String {
|
||||
val geocoder = Geocoder(this, Locale.getDefault())
|
||||
|
||||
return try {
|
||||
val addresses = geocoder.getFromLocation(
|
||||
location.latitude,
|
||||
location.longitude,
|
||||
1
|
||||
)
|
||||
|
||||
if (addresses != null && addresses.isNotEmpty()) {
|
||||
val address = addresses[0]
|
||||
"${address.locality}, ${address.subLocality}, ${address.thoroughfare}"
|
||||
} else {
|
||||
"${location.latitude.roundToInt()}, ${location.longitude.roundToInt()}"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "无法解析地址: ${e.message}")
|
||||
"${location.latitude.roundToInt()}, ${location.longitude.roundToInt()}"
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLocationString(): String {
|
||||
val location = getCurrentLocation()
|
||||
return if (location != null) {
|
||||
getAddressFromLocation(location)
|
||||
} else {
|
||||
"未知位置"
|
||||
}
|
||||
}
|
||||
|
||||
private fun addWatermarkToBitmap(originalBitmap: Bitmap): Bitmap {
|
||||
val timestamp = SimpleDateFormat("yyyy年-MM月-dd日 HH:mm:ss", Locale.getDefault()).format(Date())
|
||||
val location = getLocationString()
|
||||
|
||||
val watermarkText = "$timestamp\n$location"
|
||||
|
||||
val mutableBitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true)
|
||||
val canvas = Canvas(mutableBitmap)
|
||||
@@ -319,13 +282,13 @@ class CameraActivity : AppCompatActivity() {
|
||||
setShadowLayer(5f, 0f, 0f, Color.BLACK)
|
||||
}
|
||||
|
||||
val textWidth = paint.measureText(watermarkText)
|
||||
val textWidth = paint.measureText(timestamp)
|
||||
val textHeight = paint.descent() - paint.ascent()
|
||||
|
||||
val x = 20f
|
||||
val y = mutableBitmap.height - textHeight - 20f
|
||||
|
||||
canvas.drawText(watermarkText, x, y, paint)
|
||||
canvas.drawText(timestamp, x, y, paint)
|
||||
|
||||
return mutableBitmap
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user