Completely remove location-related code: delete LocationManagerHelper and clean up imports
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package com.example.app
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ContentValues
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
@@ -32,7 +32,6 @@ import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class CameraActivity : AppCompatActivity() {
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
package com.example.app
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.location.Location
|
||||
import android.location.LocationManager
|
||||
import android.os.Looper
|
||||
import androidx.core.app.ActivityCompat
|
||||
import com.google.android.gms.location.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* 位置服务管理器
|
||||
* 处理位置获取、地理编码等功能
|
||||
*/
|
||||
class LocationManagerHelper(private val context: Context) {
|
||||
|
||||
private var fusedLocationClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context)
|
||||
private var locationCallback: LocationCallback? = null
|
||||
|
||||
/**
|
||||
* 获取最后一次已知位置
|
||||
*/
|
||||
fun getLastKnownLocation(onResult: (Location?) -> Unit) {
|
||||
if (!hasLocationPermissions()) {
|
||||
onResult(null)
|
||||
return
|
||||
}
|
||||
|
||||
fusedLocationClient.lastLocation
|
||||
.addOnSuccessListener { location ->
|
||||
onResult(location)
|
||||
}
|
||||
.addOnFailureListener {
|
||||
onResult(null)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时获取位置
|
||||
*/
|
||||
fun requestLocationUpdates(callback: (Location?) -> Unit) {
|
||||
if (!hasLocationPermissions()) {
|
||||
callback(null)
|
||||
return
|
||||
}
|
||||
|
||||
val locationRequest = LocationRequest.create().apply {
|
||||
interval = TimeUnit.SECONDS.toMillis(10) // 每10秒更新一次
|
||||
fastestInterval = TimeUnit.SECONDS.toMillis(5) // 最快5秒更新一次
|
||||
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
|
||||
}
|
||||
|
||||
locationCallback = object : LocationCallback() {
|
||||
override fun onLocationResult(locationResult: LocationResult) {
|
||||
val location = locationResult.lastLocation
|
||||
callback(location)
|
||||
}
|
||||
}
|
||||
|
||||
fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback!!, Looper.getMainLooper())
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止位置更新
|
||||
*/
|
||||
fun stopLocationUpdates() {
|
||||
locationCallback?.let {
|
||||
fusedLocationClient.removeLocationUpdates(it)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查位置权限
|
||||
*/
|
||||
private fun hasLocationPermissions(): Boolean {
|
||||
return (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED ||
|
||||
ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查GPS是否开启
|
||||
*/
|
||||
fun isGPSEnabled(): Boolean {
|
||||
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
|
||||
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user