Remove location permissions and dependencies; switch to release build with signing for Huawei compatibility

This commit is contained in:
xiajiid
2026-02-08 17:43:08 +08:00
parent 013eeeb548
commit 490d152e84
4 changed files with 29 additions and 50 deletions

View File

@@ -23,11 +23,33 @@ jobs:
- name: Grant execute permission for gradlew - name: Grant execute permission for gradlew
run: chmod +x gradlew run: chmod +x gradlew
- name: Build with Gradle - name: Generate debug keystore for release signing
run: ./gradlew assembleDebug run: |
keytool -genkeypair \
-keystore debug.keystore \
-storepass android \
-alias androiddebugkey \
-keypass android \
-keyalg RSA \
-keysize 2048 \
-validity 10000 \
-dname "CN=Android Debug,O=Android,C=US"
- name: Configure signing for release build
run: |
echo "android.enableJetifier=true" >> gradle.properties
echo "android.useAndroidX=true" >> gradle.properties
echo "org.gradle.parallel=true" >> gradle.properties
echo "android.debug.keystore=debug.keystore" >> gradle.properties
echo "android.debug.storePassword=android" >> gradle.properties
echo "android.debug.keyPassword=android" >> gradle.properties
echo "android.debug.keyAlias=androiddebugkey" >> gradle.properties
- name: Build release APK
run: ./gradlew assembleRelease
- name: Upload APK - name: Upload APK
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: app-debug name: app-release
path: app/build/outputs/apk/debug/app-debug.apk path: app/build/outputs/apk/release/app-release.apk

View File

@@ -51,9 +51,6 @@ dependencies {
// CameraX Extensions (Effects) - Optional // CameraX Extensions (Effects) - Optional
implementation "androidx.camera:camera-extensions:${camerax_version}" implementation "androidx.camera:camera-extensions:${camerax_version}"
// Google Play Services for location
implementation 'com.google.android.gms:play-services-location:21.0.1'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

View File

@@ -6,9 +6,6 @@
<!-- 相机权限 --> <!-- 相机权限 -->
<uses-permission android:name="android.permission.CAMERA" /> <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" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" /> <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />

View File

@@ -40,8 +40,7 @@ class CameraActivity : AppCompatActivity() {
private const val TAG = "LogCam" private const val TAG = "LogCam"
private const val REQUEST_CODE_PERMISSIONS = 10 private const val REQUEST_CODE_PERMISSIONS = 10
private val REQUIRED_PERMISSIONS = arrayOf( private val REQUIRED_PERMISSIONS = arrayOf(
Manifest.permission.CAMERA, Manifest.permission.CAMERA
Manifest.permission.ACCESS_FINE_LOCATION
) )
} }
@@ -51,8 +50,6 @@ class CameraActivity : AppCompatActivity() {
private lateinit var photoPreviewLayout: LinearLayout private lateinit var photoPreviewLayout: LinearLayout
private var imageCapture: ImageCapture? = null private var imageCapture: ImageCapture? = null
private lateinit var cameraExecutor: ExecutorService private lateinit var cameraExecutor: ExecutorService
private var locationManagerHelper: LocationManagerHelper? = null
private var currentLocation: Location? = null
// 存储拍摄的图片URI // 存储拍摄的图片URI
private val capturedImageUris = mutableListOf<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 { private fun addWatermarkToBitmap(originalBitmap: Bitmap): Bitmap {
val timestamp = SimpleDateFormat("yyyy年-MM月-dd日 HH:mm:ss", Locale.getDefault()).format(Date()) 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 mutableBitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true)
val canvas = Canvas(mutableBitmap) val canvas = Canvas(mutableBitmap)
@@ -319,13 +282,13 @@ class CameraActivity : AppCompatActivity() {
setShadowLayer(5f, 0f, 0f, Color.BLACK) setShadowLayer(5f, 0f, 0f, Color.BLACK)
} }
val textWidth = paint.measureText(watermarkText) val textWidth = paint.measureText(timestamp)
val textHeight = paint.descent() - paint.ascent() val textHeight = paint.descent() - paint.ascent()
val x = 20f val x = 20f
val y = mutableBitmap.height - textHeight - 20f val y = mutableBitmap.height - textHeight - 20f
canvas.drawText(watermarkText, x, y, paint) canvas.drawText(timestamp, x, y, paint)
return mutableBitmap return mutableBitmap
} }